Height of ListView fills the whole screen, although set as wrap_content

前端 未结 2 1061
误落风尘
误落风尘 2021-01-11 20:07

i have this ListView inside a LinearLayout:




        
相关标签:
2条回答
  • 2021-01-11 20:34

    You shouldn't use wrap_content for the height of a ListView. wrap_content means "make me as large as needed to hold all of my children." When you consider that your data set could be potentially very large, that should sound like a pretty bad idea. Since you are using a LinearLayout, give your ListView layout_height="0dp" and layout_weight="1".

    It's okay to let the ListView take the remainder of the screen. If it only has one row, it will show one row, no big deal. Unless you are trying to show something below the list, but what I've told you above should accomplish that.

    0 讨论(0)
  • 2021-01-11 20:47

    If above doesn't work, you can just use RelativeLayout instead of linear and put the ListView underneath the EditText.

    0 讨论(0)
提交回复
热议问题