Android height wrap_具有固定比率的内容

Android height wrap_具有固定比率的内容,android,listview,height,android-linearlayout,android-wrap-content,Android,Listview,Height,Android Linearlayout,Android Wrap Content,我的XML文件有一个LinearLayout包含两个ListView和android:height=“wrap\u content”。但是,当其中一个列表视图的内容过多时,它会推送另一个列表视图,并占用其空间。我该怎么做才能使它在一定高度停止推动?我已尝试添加布局权重或最大高度,但没有帮助。如果您希望两个列表视图等分的数量相同,只需将它们放在线性布局中即可 LinearLayout将具有属性weightSum=2,而两个列表视图都将具有属性,具体取决于LinearLayout-orientati

我的
XML
文件有一个
LinearLayout
包含两个
ListView
android:height=“wrap\u content”
。但是,当其中一个
列表视图
的内容过多时,它会推送另一个
列表视图
,并占用其空间。我该怎么做才能使它在一定高度停止推动?我已尝试添加
布局权重
最大高度
,但没有帮助。

如果您希望两个
列表视图
等分的数量相同,只需将它们放在
线性布局中即可

LinearLayout
将具有属性
weightSum=2
,而两个
列表视图都将具有属性,具体取决于
LinearLayout-orientation属性

如果
vertical
->两个
列表视图都将具有
android:height=“0dp”
layout weight=1

如果
水平
->两个
列表视图都将具有
android:width=“0dp”
布局权重=1
请尝试以下操作:

<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>


我通过编程解决了这个问题。似乎
XML
对动态高度没有太多控制。我将
onLayoutChangedListener
添加到两个
列表视图
,以检测高度变化并在侦听器中添加高度控制逻辑。

如果要使用
布局重量
,请尝试将高度设置为
匹配父项
或0dp@PriyankVadariya有趣的是,
match\u parent
和0dp之间有什么区别?笔记本电脑不在我身边,所以我无法测试。如果你能解释一下,那就太好了。嗨,我希望他们能随心所欲地扩张,但总有一天会停止扩张
android:height=“0dp”
将根据体重确定他们的身高。