[英]Hide View element with zero height and width in android studio
I have two ListView and I want them to share the same layout position so when I click a button one ListView hides. 我有两个ListView,我希望它们共享相同的布局位置,因此当我单击按钮时,一个ListView隐藏了。 Maybe this is not possible or there is a better way like fragments? 也许这是不可能的,或者有更好的方法来处理碎片?
Use FrameLayout
. 使用FrameLayout
。 This layout view overlies two views over each other. 此布局视图彼此重叠在两个视图上。
<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>
For showing the first page (ie the first ListView
): 用于显示第一页(即第一个ListView
):
findViewById(R.id.list1).setVisibility(View.VISIBLE);
findViewById(R.id.list2).setVisibility(View.GONE);
And for the second page: 对于第二页:
findViewById(R.id.list1).setVisibility(View.GONE);
findViewById(R.id.list2).setVisibility(View.VISIBLE);
fragments are the easy way to do this IF you don't plan on changing the data in your views. 如果您不打算更改视图中的数据,则片段是执行此操作的简便方法。
Make a button and 制作一个按钮,然后
/*create fragment of the opposite view, probably through a boolean field and an if block
then*/
getSupportFragmentManager.beginTransaction().replace(/*your fragments*/).commit().
in your onclicklistener. 在您的onclicklistener中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.