0

In my xml file , i have one linearLayout and a button. The linearLayout contains a lot of textViews and checkboxes. So i wanted these textViews and checkboxes to scroll but the button should remain at its place i.e it should not scroll with the textViews. For this purpose, i cover my linearLayout with scrollView 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"
    android:background="@drawable/homeo11" >
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
          <LinearLayout 
             android:id="@+id/nexttodetail"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="vertical" 
             android:layout_marginTop="10dp">

          </LinearLayout>
    </ScrollView>>

   <Button   android:id="@+id/Next4"
            android:layout_gravity="right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Next" />

 </LinearLayout>

But doing this , hid my button. means the textviews and checkboxes are now scrolling properly but i can't see my next button. I try replacing the scrollView layout:height from fill_parent to wrap_content but this didn't work as well. Any help?

2
  • 1
    use android:layout_weight="1" in scrollbar and button Commented Nov 2, 2014 at 7:15
  • 3
    If you instead user RelativeLayout as your outermost layout, you can use android:layout_alignParentBottom="true" inside the button to keep it at Bottom and always visible. Commented Nov 2, 2014 at 7:22

1 Answer 1

1

Use a RelativeLayout as your root View and then set your component with align_above, align_parent_top and align_parent_bottom like this:

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"      
        android:layout_above="@+id/Next4" >       
            <LinearLayout 
                android:id="@+id/nexttodetail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" 
                android:layout_marginTop="10dp">

                    (...)

            </LinearLayout>
    </ScrollView>>

   <Button  
       android:id="@+id/Next4"
       android:layout_gravity="right"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"     
       android:layout_marginTop="10dp"
       android:text="Next" />

 </RelativeLayout>
Sign up to request clarification or add additional context in comments.

1 Comment

Tried your code but using this hide my linearLayout stuff!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.