簡體   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