【发布时间】:2013-05-08 18:30:56
【问题描述】:
我有一个列表的自定义行视图。假设有 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 是可变高度变量。 父母的身高仍然受到影响。有什么解决办法吗?
【问题讨论】:
-
您能否提供更多细节:1)还有其他孩子(兄弟姐妹)吗? 2) linearlayout 父级是布局的父级,还是嵌入在另一个布局中(如果是,该父级的 layout_height 设置是什么)? 3) 你是否曾经将 x 设置为大于 150dp(你的父母身高)?
-
1) 嘿,还有其他兄弟姐妹,但没有什么相互依赖 2)Linearlayout 是根布局,它没有任何父布局 3)不,我从来没有设置 x>150
标签: android android-layout layout resize