How to scroll layout which have 3 list view

后端 未结 5 774
情歌与酒
情歌与酒 2021-02-08 02:13

I have one layout. This layout contain 3 list view with the height of wrap_content data in the Listview are not fix. When Listview have a liitel huge data at that time the data

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-08 02:36

    If you are presenting stuff in a vertical or horizontal stack, you should be using LinearLayout and then use the layout_weight attribute to control the proportions of the individual rows/columns within the container.

    If you want screen-sized, set the layout_width and layout_height to fill_parent otherwise you will not get all available screen dimension. If you try to use wrap_content for height, everything will collapse, unless you resort to additional layout constraints, e.g. minHeight.

    We use this everywhere and it is quite reliable. For three items, you can use 1/1/1 or 3/3/3.

    The weights also do not have to be equal! You can divide up the proportions any way you wish; the weights are just relative ratios of the entire span (width/height). E.g. if you want the middle element twice the size, use 1/2/1; if you want it 40% use 30/40/30 or 3/4/3.

    A good "trick" is to use layout_weight=1 on exactly one row/column (others default to zero), and it will "fill-in" any remaining space. This is a common layout scenario.

    If you need the stack to be scrollable, you can put it into a ScrollView. In this case, you must set the layout_height of the LinearLayout to wrap_content, and you will be subject collapsing depending on the whim of the layout system (meaning you need to then use min/max constraints).

提交回复
热议问题