【发布时间】:2020-08-15 05:23:18
【问题描述】:
我有一个片段屏幕,其中包含两个部分 1) 图像卡和 2) 带有视图寻呼机的选项卡布局,它们被分成两个 XML 文件和两个片段生命周期 java 文件。此外,我的活动中有一个 NAV 主机片段和一个 NAV 图表。我可以在 NAV 主机片段中同时启动这两个 XML,这样我就可以垂直显示这两个 XML,第 1) 和 2) 部分。
备注:我没有空间添加/创建 XML/NAVHostFragment 以包含两个 XML。 Java 中的任何东西都对我有用。
有人知道在这种情况下如何做到这一点吗?
这是我开始的:
activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_scrollFlags="scroll">
<fragment
android:id="@+id/navhostfragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/navgraph" />
</LinearLayout>
imagecard.xml
<androidx.cardview.widget.CardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</androidx.cardview.widget.CardView>
viewpager.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
【问题讨论】:
标签: android android-fragments navigation