3

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!

1
  • I think I know what's going on, but I don't want to provide an answer until I see your layout.xml. Can you post it? Commented Jun 6, 2014 at 14:52

3 Answers 3

1

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> 
Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't work, the checkbox stays at the bottom, when the scrollview is barely filled
@raybaybay If the answer doesn't work, why mark it as the accepted answer? This will be misleading for other readers in the future.
0

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> 

Comments

0

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> 

1 Comment

But that doesnt help the fact that the checkbox must be directly under the scrollview when it is barely filled

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.