【发布时间】:2019-01-23 09:20:44
【问题描述】:
这是一个简单的导航设置示例,经过一段时间的研究,我无法使用导航组件库。
顶部的sticky fragment和底部的fragment在各自的导航图中,这里是main_activity.xml:
<androidx.constraintlayout.widget.ConstraintLayout
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="match_parent">
<fragment
android:id="@+id/nav_sticky_top"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/navigation_graph_sticky_top" />
<fragment
android:id="@+id/navigation_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/nav_sticky_top"
app:navGraph="@navigation/navigation_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
当我按下“导航到同级片段”时,它会导航到底部导航图中的同级片段,这是正确的,结果:
这是navigation_graph.xml:
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation_graph.xml"
app:startDestination="@id/blankFragment1">
<fragment
android:id="@+id/blankFragment1"
android:name="com.example.myapplication.BlankFragment1"
android:label="fragment_blank_fragment1"
tools:layout="@layout/fragment_blank_fragment1">
<action
android:id="@+id/action_blankFragment1_to_siblingFragment"
app:destination="@id/siblingFragment" />
</fragment>
<fragment
android:id="@+id/siblingFragment"
android:name="com.example.myapplication.SiblingFragment"
tools:layout="@layout/fragment_sibling_fragment" />
</navigation>
现在我想实现“导航到全屏片段”按钮,该按钮应该导航到一个单独的第三个导航图中的全屏片段,并且应该位于粘性片段导航图和其下方的导航图之上。如何正确实现这一目标?我的意思是 没有 hack,比如将顶部导航图片段的可见性设置为 GONE 并在底部导航图中导航到全屏片段。
【问题讨论】:
标签: android android-architecture-components android-architecture-navigation