繁体   English   中英

在Android Studio中隐藏高度和宽度为零的View元素

[英]Hide View element with zero height and width in android studio

我有两个ListView,我希望它们共享相同的布局位置,因此当我单击按钮时,一个ListView隐藏了。 也许这是不可能的,或者有更好的方法来处理碎片?

使用FrameLayout 此布局视图彼此重叠在两个视图上。

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/list1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>

    <ListView
        android:id="@+id/list2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>

</FrameLayout>

用于显示第一页(即第一个ListView ):

findViewById(R.id.list1).setVisibility(View.VISIBLE);
findViewById(R.id.list2).setVisibility(View.GONE);

对于第二页:

findViewById(R.id.list1).setVisibility(View.GONE);
findViewById(R.id.list2).setVisibility(View.VISIBLE);

如果您不打算更改视图中的数据,则片段是执行此操作的简便方法。

制作一个按钮,然后

/*create fragment of the opposite view, probably through a boolean field and an if block
then*/
getSupportFragmentManager.beginTransaction().replace(/*your fragments*/).commit().

在您的onclicklistener中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM