Search code examples
androidnavigationfragment

Is there anyway to show fragment preview of navigation.xml in Landscape?


Is there any way to show the fragment previews in navigation.xml in Landscape?

I wanted to use navigation.xml to show what are the current navigation between different fragments of code, however the screenOrientation is basically landscape, it is not the same in navigation.xml view in Android Studio. any idea?

<activity
    android:name="MainActivity"
    android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
    android:theme="@style/SplashTheme"
    android:screenOrientation="userLandscape"
    android:resizeableActivity="false"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<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"
    app:startDestination="@id/loginFragment">

    <fragment
        android:id="@+id/loginFragment"
        android:name="LoginFragment"
        android:label="LoginFragment"
        tools:layout="@layout/fragment_login">
        <action
            android:id="@+id/action_loginFragment_to_welcomeFragment"
            app:destination="@id/welcomeFragment"
            app:enterAnim="@anim/fragment_fade_enter"
            app:exitAnim="@anim/fragment_fade_exit"
            app:popUpTo="@id/loginFragment"
            app:popUpToInclusive="true"/>
    </fragment>
    <fragment
        android:id="@+id/welcomeFragment"
        android:name="WelcomeFragment"
        android:label="WelcomeFragment"
        tools:layout="@layout/fragment_welcome">
        <action
            android:id="@+id/action_welcomeFragment_to_insertCodeFragment"
            app:destination="@id/insertCodeFragment"
            app:enterAnim="@anim/fragment_fade_enter"
            app:exitAnim="@anim/fragment_fade_exit" />
        <action
            android:id="@+id/action_welcomeFragment_to_hostFragment"
            app:destination="@id/hostFragment"
            app:enterAnim="@anim/fragment_fade_enter"
            app:exitAnim="@anim/fragment_fade_exit"/>
    </fragment>
    <fragment
        android:id="@+id/insertCodeFragment"
        android:name="InsertCodeFragment"
        android:label="InsertCodeFragment"
        tools:layout="@layout/fragment_code">
        <action
            android:id="@+id/action_insertCodeFragment_to_successFragment"
            app:destination="@id/successFragment"
            app:enterAnim="@anim/fragment_fade_enter"
            app:exitAnim="@anim/fragment_fade_exit" />
        <action
            android:id="@+id/action_insertCodeFragment_to_hostFragment"
            app:destination="@id/hostFragment" />

    </fragment>
    <fragment
        android:id="@+id/hostFragment"
        android:name="HostFragment"
        android:label="HostFragment"
        tools:layout="@layout/fragment_host">
        <action
            android:id="@+id/action_hostFragment_to_insertDataFragment"
            app:destination="@id/insertDataFragment"
            app:enterAnim="@anim/fragment_fade_enter"
            app:exitAnim="@anim/fragment_fade_exit" />
    </fragment>
    <fragment
        android:id="@+id/insertDataFragment"
        android:name="InsertDataFragment"
        android:label="InsertDataFragment"
        tools:layout="@layout/fragment_data">
        <action
            android:id="@+id/action_insertDataFragment_to_successFragment"
            app:destination="@id/successFragment"
            app:enterAnim="@anim/fragment_fade_enter"
            app:exitAnim="@anim/fragment_fade_exit"
            app:popUpTo="@id/insertDataFragment" />
        <argument
            android:name="host_id"
            app:argType="integer"
            android:defaultValue="0" />
    </fragment>
    <fragment
        android:id="@+id/successFragment"
        android:name="SuccessFragment"
        android:label="SuccessFragment"
        tools:layout="@layout/fragment_success">
        <action
            android:id="@+id/action_successFragment_to_welcomeFragment"
            app:destination="@id/welcomeFragment"
            app:popUpTo="@id/successFragment"
            app:popUpToInclusive="true" />
        <argument
            android:name="host_name"
            app:argType="string" />
        <argument
            android:name="visitor_name"
            app:argType="string" />
    </fragment>
</navigation>

Solution

  • Toggle to landscape

    Android studio Giraffe has a drop down to toggle between potrait and landscape

    I read here that from android 4.1.1 you can toggle them by clicking the letter 'O'