0

I have screen with 18 buttons, Is it possible to make this group of buttons scrollable so that user can see buttons which are out of the viewable area. I tried putting these buttons in ScrollView but got the exception that only their can be only 1 child of scroll view.

Currently the buttons are present in a RelativeLayout like:

<Button
    android:id="@+id/btnChapter2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnChapter1"
    android:layout_below="@+id/btnChapter1"
    android:text="Chapter 2" />

<Button
    android:id="@+id/btnChapter3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnChapter2"
    android:layout_below="@+id/btnChapter2"
    android:text="Chapter 3" />

<Button
    android:id="@+id/btnChapter4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnChapter3"
    android:layout_below="@+id/btnChapter3"
    android:text="Chapter 4" />

<Button
    android:id="@+id/btnChapter5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnChapter4"
    android:layout_below="@+id/btnChapter4"
    android:text="Chapter 5" />

<Button
    android:id="@+id/btnChapter6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/btnChapter5"
    android:layout_below="@+id/btnChapter5"
    android:text="Chapter 6" />

The current screen with buttons 9, 17 and 18 being screwed up looks as:

enter image description here

4

1 回答 1

1

Well, ScrollView may have only one child. In this case, put a LinearLayout or RelativeLayout as the ScrollView's child. The put your button inside the LinearLayout or RelativeLayout. That should've done it. Example code:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>
</ScrollView>
于 2013-03-30T17:27:35.423 回答