DaveDev
DaveDev

Reputation: 42175

How to make text scroll and keep other elements fixed to the bottom of the screen?

I'm trying to create the following display, where the text scrolls and the other elements are fixed to the bottom of the screen:

enter image description here

However, it is appearing as follows, where the text doesn't scroll and it's pushing the elements off the screen.:

enter image description here

This is the layout I'm using:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget32"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center">
    <ScrollView
        android:id="@+id/scroller"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <TextView
            android:id="@+id/txtTC"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:paddingLeft="20dp"
            android:layout_alignParentLeft="true" />
    </ScrollView>
    <CheckBox
        android:id="@+id/chkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_gravity="center"
        android:text="Don't Show Again"
        android:layout_below="@+id/scroller" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/chkBox"
        android:layout_alignParentBottom="true">
        <RelativeLayout
            android:id="@+id/btnCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:orientation="vertical"
            android:layout_weight="1">
            <ImageButton
                android:id="@+id/imgCancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:paddingTop="0dip"
                android:src="@drawable/stop"
                android:paddingBottom="5dip"
                android:paddingRight="5dip"
                android:background="@drawable/common_button" />
            <TextView
                android:id="@+id/txtCancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:layout_below="@id/imgCancel"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="OK"
                android:textStyle="bold" />
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

What do I need to do to make the text scroll and the other elements fixed to the bottom of the screen?

Upvotes: 0

Views: 480

Answers (2)

Minhaj Arfin
Minhaj Arfin

Reputation: 1041

You should add the ScrollView Containing the TextView inside a Layout(Linear would do). I hope it helps

Upvotes: 0

dinesh sharma
dinesh sharma

Reputation: 3332

Try replacing this xml code and apply images where you need

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget32"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#5555"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="25dp" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Terms and Conditions"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ScrollView
        android:id="@+id/scroller"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

    <TextView
        android:id="@+id/txtTC"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingLeft="20dp"
        android:textSize="20sp" />

    </ScrollView>

    <CheckBox
        android:id="@+id/chkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/scroller"
        android:layout_gravity="center_vertical"
        android:text="Don&apos;t Show Again" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/chkBox"
        android:layout_alignParentBottom="true">
        <RelativeLayout
            android:id="@+id/btnCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:orientation="vertical"
            android:layout_weight="1">
            <ImageButton
                android:id="@+id/imgCancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:paddingTop="0dip"
                android:paddingBottom="5dip"
                android:paddingRight="5dip" />
            <TextView
                android:id="@+id/txtCancel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:layout_below="@id/imgCancel"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:text="OK"
                android:textStyle="bold" />
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

Upvotes: 1

Related Questions