代码之家  ›  专栏  ›  技术社区  ›  Jonathan

相对布局展开但不收缩[重复]

  •  0
  • Jonathan  · 技术社区  · 6 年前

    我有一个 RelativeLayout 通过设置 LinearLayout 在里面 View.VISIBLE . 这很好,但是一旦我将linearlayout设置为invisible,ll就会隐藏,但父级relativelayout保持其大小。

    在扩展以供以后恢复之前,我真的需要存储layoutParam吗,还是有一些内置的魔力可以在扩展过程中自动收缩大小?


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

    列表适配器.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);
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Jay Thakkar    6 年前

    使用 跑了 而不是 隐形的

    v.findViewById(R.id.expandArea).setVisibility(View.GONE);