Reputation: 4746
I have a few views that I have to place in a 4 x 6 grid. Each of the views should have the same width w and same height h and fill the screen. What I want is to use GridLayout or GridView to draw these.
I know that I can use the stretchMode = "columnWidth" in GridView which sets equal width to each of its children. I also want it to set equal height and fill the screen vertically.
Can I achieve this by using any of GridView or if not possible then GridLayout? I am looking for GridView before switching to LinearLayouts and using weights because I have custom views as the grid items and I would love to use adapters rather than coding for each element.
Upvotes: 0
Views: 2409
Reputation: 4746
I did a custom layout which extends linear layout. I found that for my case this is a better approach and I had more control over all the touch events on the layout and the children themselves.
Upvotes: 0
Reputation: 851
You can still use Adapters
with LinearLayouts
or TableLayout
, you just have to add the views programatically and call the getView() method yourself. GridView
is more meant for a dynamic number of items and handles its own scrolling.
This can be done using something like this in your onCreateView() or whatever:
mAdapter = new FooAdapter();
mList = (LinearLayout) v.findViewById(R.id.list);
for(int i = 0; i< mAdapter.getCount(); i++){
View child = mAdapter.getView(i, null, mList);
mList.addView(child);
}
If you are possibly just changing the data, passing the old views as convertViews may speed things up.
Upvotes: 1