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

前端 未结 12 956
小蘑菇
小蘑菇 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:51

    Attention! Correct way to calculate height is not

    params.height = getCount() * (old_count > 0 ? getChildAt(0).getHeight() : 0);
    

    We have to add height of each (minus one) divider heights.

    if(oldCount > 0 && getCount() > 0)
        params.height = getCount()
                      * (getChildAt(0).getHeight() + getDividerHeight())
                      - getDividerHeight();
    else
        params.height = 0;
    

提交回复
热议问题