Reputation: 31
I have to create Table Layout dynamically in android. First one header for one row, second one two column for another row in Table Layout.
https://i.sstatic.net/hKEyk.jpg
Upvotes: 0
Views: 77
Reputation: 1609
Ok. So your main concern about to show header with gridview. Simplest way to show as per your requirement is to use Recyclerview with GridLayoutManager.
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
GridLayoutManager glm = new GridLayoutManager(this, 2);
glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position % 4 == 0) {
return 2; // row with single column.
} else {
return 1; // row with two column.
}
}
);
mRecyclerView.setLayoutManager(glm);
mRecyclerView.setAdapter(mAdapter);
You will get following output.
I hope this will you.
Upvotes: 2