0

Here is how I did it with the 23.2.0 RecyclerView.

TextView textView = new TextView(getActivity());
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setText("GO SYNC CONTACTS!!!!!");
textView.setTextSize(30);

Then I add this view to the first position of my RecyclerView in adapter.

Turns out there's a big empty space of this TextView. Other views which are inflated by XML works just fine.

Zijian Wang
  • 334
  • 2
  • 7
  • Have you checked this question? http://stackoverflow.com/questions/35726839/recyclerview-doesnt-respect-height-wrap-content – hehe Mar 09 '16 at 06:00
  • Please [check this](http://stackoverflow.com/questions/27475178/how-do-i-make-wrap-content-work-on-a-recyclerview/35623177#35623177) answer. – Amit Vaghela Mar 09 '16 at 06:27

1 Answers1

0

I think u should set params fro the parent of the TextView not for the ActualView(TextView),Try this once and let me know

ParentOfYoyrTextView.LayoutParams paramsExample = new ParentOfYoyrTextView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT;
Naveen Shriyan
  • 1,266
  • 1
  • 9
  • 15
  • Thanks for reply, since the the TextView is a direct child of RecyclerView, so I'm assuming it is a ViewGroup kind of LayoutParams? I also tried RecyclerView.LayoutParams, still not working. But I also tried inflate a XML file outside the adapter(in fragment), and pass the inflated view to the adapter, and still not working. I think that's something wrong this the Parent View. I'll keep look into this problem. Thanks! – Zijian Wang Mar 09 '16 at 07:25
  • set black color to your text view once and check pls. – Naveen Shriyan Mar 09 '16 at 07:28