Search code examples
androidandroid-layoutandroid-scrollview

Not all views are scrolling


I apologize, I'm still derping even after consulting SO solutions: (1) ScrollView causes the App to crash (2) Adding scrollview crashes app (3) App crashing after adding a ScrollView and ImageView (4) Add a ScrollView in Linear and Relative Layout in one XML file --- etc.

Here's my situation:

[--Subject--------------]

[--Labels---------------]

[--Participants--------]

{ mail message #1 }

{ mail message #2 }

{ mail message #3 }

Current Behavior: When I scroll, the {mail messages} move up, but [Subject-Labels-Participants] stays put as a stationary header.

Desired Behavior: When I scroll, the [Subject-Labels-Participants] and {messages} move as one elegant unit, scrolling out of view just like magical unicorns dancing off into the sunset.

Code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true">

        <RelativeLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="75dp"
        android:orientation="vertical">

        <TextView
        android:id="@+id/subject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingLeft="13dp"
        android:text="Subject"
        android:textSize="20sp"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/labels_row"
        android:layout_below="@id/subject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="4dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/labels_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="17dp"
            android:src="@drawable/label" />

        <TextView
            android:id="@+id/labels"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="44dp"
            android:text="Labels" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/participants_row"
        android:layout_below="@id/labels_row"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="4dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/participants_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="13dp"
            android:src="@drawable/participants" />

        <TextView
            android:id="@+id/participants"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="44dp"
            android:text="Participants" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/mails"
        android:layout_below="@id/participants_row"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

                </RelativeLayout>



</ScrollView>

    <RelativeLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="25dp"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/compose_reply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/text_reply" />

        <View
            android:id="@+id/reply_divider"
            android:layout_toRightOf="@id/compose_reply"
            android:layout_width="1dp"
            android:layout_height="48dp"
            android:layout_marginTop="1dp"
            android:layout_marginRight="-1dp"
            android:layout_marginBottom="1dp"
            android:layout_marginLeft="-1dp"
            android:background="#CED0D1" />

        <ImageButton
            android:id="@+id/voice_reply"
            android:layout_toRightOf="@id/reply_divider"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/voice_input" />

        <Spinner
            android:id="@+id/touch_reply"
            style="?android:attr/buttonStyleSmall"
            android:layout_toRightOf="@id/voice_reply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</RelativeLayout>

Solution

  • If you want

    Desired Behavior: When I scroll, the [Subject-Labels-Participants] and {messages} move as one elegant unit, scrolling out of view just like magical unicorns dancing off into the sunset.

    Then put everything into 1 RelativeView, within 1 ScrollView

    e.g.

    <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" >
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
    
            More Views
    
            More Layouts
    
            More Views
    
            More Layouts
    
    
        </RelativeLayout>
    
    </ScrollView>