Search code examples
androidxmlformattingscrollviewdimensions

If ScrollView only supports one direct child, how am I supposed to make a whole layout scrollable?


I have 3 text views in a layout, where the text clips a tad on the bottom on my droid 2... How can I ensure that the whole text is viewable, and the user can scroll down (simply with their finger), to see the rest of my text?

Thanks!

EDIT:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageButton android:id="@+id/ImageButton01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/def" 
    android:layout_gravity="top|center">
    </ImageButton>

<TextView android:id="@+id/oneView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/one_def" 
android:layout_gravity="left|center" 
android:textSize="13dip"></TextView>

<TextView android:text="@string/two_def" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="left|center" 
android:id="@+id/twoView" 
android:textSize="13dip"></TextView>

<TextView android:text="@string/threedef_def" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="left|center" 
android:id="@+id/threeView" 
android:textSize="13dip"></TextView>


</LinearLayout>

Solution

  • Just wrap your current LinearLayout with ScrollView. So it should be smth like this:

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