Search code examples
javaandroidandroid-layoutandroid-viewandroid-scrollview

Android scrollable layout - views not visible on orientation change


My XML scrollable layout (work in progress) looks like this:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        >
    </ListView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tvStatus"
            android:text="0 SMS found"
            android:textSize="15sp"
            android:layout_width="120dp"
            android:layout_height="wrap_content"  />
        <Button
            android:id="@+id/btnExport"
            android:layout_width="88dp"
            android:layout_height="wrap_content"
            android:text="Export"
            />
    </LinearLayout>
</LinearLayout>
</ScrollView>

When load app on testing device in portrait mode, all views are presented and visible: portrait mode When device orientation is changed to horizontal, only listview part of layout is visible (?!?): landscape mode Does anybody has clue on what possibly is going on here? Thanks.


Solution

  • This is the layout you need:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        </ListView>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/tvStatus"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:text="0 SMS found"
                android:textSize="15sp"/>
    
            <Button
                android:id="@+id/btnExport"
                android:layout_width="88dp"
                android:layout_height="wrap_content"
                android:text="Export"
                />
        </LinearLayout>
    
    </LinearLayout>
    

    You can also view how will your layout be in landscape mode while constructing it:

    enter image description here