Android - Multiple fragments in ONE tab

后端 未结 1 1099
清歌不尽
清歌不尽 2021-01-20 05:53

I searched a lot in the web about the possibility to have multiple fragments in one action bar tab.

This question comes closest to my needs but the code is not worki

相关标签:
1条回答
  • 2021-01-20 06:33

    I was looking for a solution to the same Topic, and found this, which comes in quite handy.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <fragment android:name="com.example.news.ArticleListFragment"
                android:id="@+id/list"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="match_parent" />
        <fragment android:name="com.example.news.ArticleReaderFragment"
                android:id="@+id/viewer"
                android:layout_weight="2"
                android:layout_width="0dp"
                android:layout_height="match_parent" />
    </LinearLayout>
    

    so Reference your Fragments and inflate it, just like a normal Fragment

    0 讨论(0)
提交回复
热议问题