0

I've made recyclerview view and also added it a header. Other contains text and images and header contains only text. In vertical it was good but in gridlayout header is also added with grid layout.

I want to be it in top and only other come in grid layout. how can i do that?

this is main acitivity:

recyclerView = (RecyclerView)findViewById(R.id.recycler);

LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));

adapter = new DataAdapter(items);
recyclerView.setAdapter(adapter);

items.add(new Header("Header 1"));
items.add(new Item(R.drawable.ic_launcher_background, "fa"));
items.add(new Item(R.drawable.ic_launcher_background, "fa"));
items.add(new Item(R.drawable.ic_launcher_background, "fa"));
items.add(new Item(R.drawable.ic_launcher_background, "fa"));
items.add(new Item(R.drawable.ic_launcher_background, "fa"));
adapter.notifyDataSetChanged();
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dibas Dauliya
  • 639
  • 5
  • 20
  • Just an idea, you can set the colspan of Header to be at the max amount of columns, This way it will fill all the top row of the Grid. You can do that by adding android:layout_columnSpan="x"( when x is the number of columns that your header will use ) to your header layout xml. I am not sure if it's the best way to solve it but it should be a nice work around. – Dor Aug 31 '19 at 07:59
  • @Dor that didn't work :( – Dibas Dauliya Aug 31 '19 at 10:02
  • Well, you can implement setSpanSizeLookUp for the LayoutManager. This way you can define the colspan based on the item position on the view. you can read more about it [here](https://stackoverflow.com/a/31095791/9233991) – Dor Aug 31 '19 at 10:32

0 Answers0