0

I have to create a listview inside a fragment that should always display the first 3 items no matter what screen size (rest should be scrollable). These 3 items should fill up the whole available space, which means that the item height has to be adjusted dynamically. You could also say: The first three items should take up about 33% of the listview each.

Is there a way achieving this using LinearLayout and layout weights? If not, what would be the best way to to this programatically, e.g. by determining current fragment size or something like that?

anti_gone
  • 973
  • 8
  • 18

3 Answers3

1

I managed to get the height and width using OnGlobalLayoutListener.

After all, we decided this wasn't a good idea layout-wise, but I thought someone might find this interesting nevertheless ;)

anti_gone
  • 973
  • 8
  • 18
0

Try using the view.setMinimumHeight(int) on the inflated layout in your list adapter and supply it with a desired height.

As for obtaining screen size you can check this SO post

Edit: Apply that method to the layout that defines each item. You need a custom adapter and do that work in your getView method

Community
  • 1
  • 1
mhenryk
  • 551
  • 5
  • 13
0

You could probably calculate the size on the fly by determining the screen size, and adjusting the height of the list items as they are created & added to the list. This question and this one might help shed also shed some light on using weights, and would clean up your code.

Community
  • 1
  • 1
lase
  • 2,508
  • 2
  • 24
  • 35