1

I have a XML Layout as follows. I have a TExt View followed by a number of check boxes and then a button. I have enclosed all the check boxes in a Linear Layout and set up a scroll view for that.`I cant view my button after scrolling down, WHat should I do ?

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


    <TextView />

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="vertical" >

        <LinearLayout>

            <CheckBox />

            <CheckBox />

            <CheckBox/>

            <CheckBox/>

            <CheckBox/>

            <CheckBox/>

            <CheckBox/>

            <CheckBox/>

            <CheckBox />

            <CheckBox/>

            <CheckBox />
        </LinearLayout>
    </ScrollView>

    <Button

    </Button>

</LinearLayout>
chitranna
  • 1,579
  • 6
  • 25
  • 42

3 Answers3

1

There is a condition for scroll view there should be only one childview for scroll view the child view may contains may sub child views

if you want to show the button you have use view wight concept

    <LinearLayout
        <TextView
    <ScrollView   
    <LinearLayout
      <CheckBox
        <CheckBox
        <CheckBox
        <CheckBox
        .



        <CheckBox
    LinearLayout>
    ScrollView>
        <Button
 android:layout_weight="1"

    LinearLayout >
Sandeep P
  • 4,291
  • 2
  • 26
  • 45
0

you have to user Relativelayout or FrameLayout for better solution.. this is the code using relative layout

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


        <Button
            android:id="@+id/relative_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
android:text="hello one"
             >
        </Button>

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@id/relative_button"
             >

         <LinearLayout>

                <CheckBox />

                <CheckBox />

                <CheckBox/>

                <CheckBox/>

                <CheckBox/>

                <CheckBox/>

                <CheckBox/>

                <CheckBox/>

                <CheckBox />

                <CheckBox/>

                <CheckBox />
            </LinearLayout>
        </ScrollView>

    </RelativeLayout>
Sandeep P
  • 4,291
  • 2
  • 26
  • 45
0

Try the following code. You need to align the Button to the bottom and the align the LinearLayout containing the checkboxes on top of the Button. I have tried this code and it works for me.

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

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="ABC" />

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_above="@+id/button"
        android:orientation="vertical" >

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

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
STT
  • 274
  • 5
  • 11