这个问题在这里已有答案:
我有一个RelativeLayout
,通过设置LinearLayout
内部到View.VISIBLE
点击扩大。这样可以正常工作,但只要我将LinearLayout设置为INVISIBLE,LL就会隐藏,但父RelativeLayout保持其大小。
我是否真的必须存储LayoutParams才能进行扩展以便以后恢复,或者是否有一些内置的魔法来自动缩小尺寸,因为它正在用于增长?
list_item.xml
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/expandArea"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
>
</RelativeLayout>
list adapter.Java
// shrinking does not work when:
v.findViewById(R.id.expandArea).setVisibility(View.INVISIBLE);
// whereas expanding works correct:
v.findViewById(R.id.expandArea).setVisibility(View.VISIBLE);
使用GONE而不是INVISIBLE
v.findViewById(R.id.expandArea).setVisibility(View.GONE);