I want to display different layout structure in portait/landscape

Asked 2 years ago, Updated 2 years ago, 41 views

I would like to implement a fixed layout for portrait and scrollable navigation menu for landscape, but even if I divide it into layout and layout-land, I get the following error.

 Wrong state class, expecting View State but received class android.widget.ScrollView $SavedState installed.
This useful happens when two views of different type have the same id in the same hierarchy.
This view's id is id /drawer_nav. Make sure other views do not use the same id.

Please let me know if there is a solution to this situation.

The layout file is as follows:

layout/drawer_nav.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/nav_container">
     <RelativeLayout/>
     <LinearLayout/>
</LinearLayout>

layout-land/drawer_nav.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView>
    <LinearLayout android:id="@+id/nav_container">
        <RelativeLayout/>
        <LinearLayout/>
    </LinearLayout>
</ScrollView>

The fastest way is to have both scrollable layouts, but only during portrait, we separate them because we want to fix some of the contents to footer.
Thank you for your cooperation.

[Additional note below]
I have added the id of the corresponding part.
Also, the activity layout of the caller is as follows:
activity_top.xml (caller)

<include
    android: id="@+id/drawer"
    layout="@layout/drawer_nav"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"/>

android

2022-09-30 19:47

1 Answers

I have solved myself, so I will leave a comment for the future.
(Actually, I was taught by an in-house Android teacher.)

layout-land/drawer_nav.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout>
  <ScrollView>
    <LinearLayout android:id="@+id/nav_container">
      <RelativeLayout/>
      <LinearLayout/>
    </LinearLayout>
  </ScrollView>
</LinearLayout>

I checked and it seems to happen if a view is included different from the caller @+id/drawer.
It was simple to understand, but I fell in love with it a little bit...


2022-09-30 19:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.