1

I'm using Navigation Component with a navGraph. I have one activity with a NavHost and I would like to have in tablet landscape mode one activity with 2 fragments. I have already read this but I'm using viewBinding and I cannot understand how I can implement this to have the same result. I found also this but the question was asked 1,5 year ago so maybe it's something new to implement that properly.

My MainActivity :

<androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_graph" />

My ListFragment :

<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFEDED"
tools:context=".ui.fragments.ListFragment">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rv_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:listitem="@layout/item_property" />

</androidx.constraintlayout.widget.ConstraintLayout>

and my ListFragment tablet land :

<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFEDED"
tools:context=".ui.fragments.ListFragment">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rv_list"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toLeftOf="@id/nav_host_fragment_tablet"
    app:layout_constraintTop_toTopOf="parent"
    tools:listitem="@layout/item_property" />

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/nav_host_fragment_tablet"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    app:defaultNavHost="false"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_weight="2"
    app:layout_constraintLeft_toRightOf="@id/rv_list"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navGraph="@navigation/nav_graph_tablet" />

</androidx.constraintlayout.widget.ConstraintLayout>
gallosalocin
  • 835
  • 1
  • 12
  • 18

0 Answers0