raybaybay
raybaybay

Reputation: 647

ScrollView throws bottom views out

I have a LinearLayout with a ScrollView inside and a checkbox underneath the scrollview. Whenever i put alot of text in the scrollview, it will expand through the whole screen and kick out the bottom checkbox view. How do i prevent that from happening?

Basically, i want the checkbox to always be right underneath the scrollview. I also want the scrollview to shrink and expand depending on its text. When theres alot of text inside, it should expand to the point where the checkbox is still visible at the bottom of the screen.

It should look like this:

enter image description here enter image description here

Where the filled ScrollView should have a scroller if the text is too much, rather than kicking out the checkbox from the screen

Help!

My layout looks like:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <!-- TextView inside --->

    </ScrollView>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:gravity="top"
        android:orientation="horizontal" >

        <!-- CheckBox inside --->

    </RelativeLayout>

</LinearLayout>

Dont worry about the syntax, or all the stuff that are inside, I wrote this quick because the code inside is really long and unnecessary!

Upvotes: 3

Views: 108

Answers (3)

PedroHawk
PedroHawk

Reputation: 630

Define a fixed size to your ScrollView. As bigger as the text becomes, the scroll is defined to that size (like layout_height="100dp")

UPDATE

Try something like this

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="200dp" >



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

           <!-- TextView's inside - -->

        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <!-- CheckBox's inside - -->

    </LinearLayout>

</LinearLayout>

Upvotes: 0

nikhil.thakkar
nikhil.thakkar

Reputation: 1093

Try this layout :

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!-- TextView inside --->

    </ScrollView>



        <!-- CheckBox Here --->



</LinearLayout>

Upvotes: 1

bstar55
bstar55

Reputation: 3624

Let's start simple. Try replacing your parent LinearLayout with a RelativeLayout. If this doesn't work, you may have to fix the height of ScrollView to some fixed height using weight, or pixels (which is non-ideal):

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <!-- TextView inside --->

    </ScrollView>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:gravity="top"
        android:orientation="horizontal" >

        <!-- Stuff inside --->

    </RelativeLayout>

</RelativeLayout>

Upvotes: 0

Related Questions