0

我的XML文件有一个包含LinearLayout两个. 但是,当其中一个内容过多时,它会推动另一个并占用其空间。我该怎么做才能让它在一定高度停止推动?我试过添加or但它没有帮助。ListViewandroid:height="wrap_content"ListViewListViewlayout-weightmaxHeight

4

3 回答 3

0

ListViews如果您想要两个均分的金额相同,只需将它们放在一个LinearLayout.

LinearLayout将拥有财产weightSum=2,而两者都ListViews将拥有,具体取决于LinearLayout orientation property

如果vertical-> 两者ListViews都会有android:height="0dp"layout-weight=1

如果horizontal-> 两者ListViews都会有android:width="0dp"layout-weight=1

于 2018-08-16T11:42:50.207 回答
0

尝试这个 :

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/green_bg_duplicate"
    android:gravity="center"
    android:orientation="vertical"
    android:weightSum="2">

    <RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1" />

    <RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1" />

</LinearLayout>
于 2018-08-16T12:40:06.960 回答
0

我通过编程解决了它。似乎XML对动态高度没有太多控制。我添加onLayoutChangedListener了两者ListView以检测高度变化并在侦听器中添加高度控制逻辑。

于 2018-08-18T07:42:17.133 回答