Calculate the size of a list view or how to tell it to fully expand

前端 未结 12 954
小蘑菇
小蘑菇 2020-11-29 00:20

I am currently trying to use a ListView inside of a ScrollView. I know from what I\'ve read that this is looked down upon, but I\'m trying to get the ListView to expand com

12条回答
  •  孤城傲影
    2020-11-29 00:50

    I know it's late and there is already and answer but if you really want to do this there is an easy way:

    Create the list view Item with a defined height

    
    
        
    
    

    Now we know that the Item is 100dp high, and if we know the number of items then it is very simple

    set the ListView height literally to the value of NoOfItems*Height + 10dp extra

    It will never change since all unites are in dp.

    If you have more than 1 item type then calculate it with basic math and set it

            
            
    

提交回复
热议问题