1

我有一个列表的自定义行视图。假设有 2 个组件,一个父级和一个子级....当我更改子级的高度时,我想保持父级的高度不变...

我已经将父高度设置为常数,并且孩子的高度是动态变化的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:background="#fff"
android:orientation="vertical" >


<RelativeLayout
    android:id="@+id/child"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/icon" />

</RelativeLayout>
</LinearLayout>

在运行时,

child.setLayoutParams(new LayoutParams(30, x);

其中 x 是一个可变高度变量。父母的身高仍然受到影响。任何解决方案?

4

1 回答 1

0

如果 LinearLayout 是根视图,当你膨胀它时,参数 android:layout_width 和 android:layout_height 由 android 更改,如果它是列表中的一行,那么它们将具有宽度 match_parent 和高度 wrap_content。如果您想为该行保持恒定的高度,则必须在膨胀视图后以编程方式设置布局参数。

于 2013-05-09T07:59:03.343 回答