Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RelativeLayout inside ScrollView with allignParentBottom

i have a fragment with a RelativLayout that holds a TextView at the top, a LinearLayout (which is filled dynammically with CheckBoxes) in the middle and a Button at the bottom.

The problem is that i need scrolling if too many CheckBoxes are added. The Button is alligned using the attribut layout_alignParentBottom and is displayed at the top of the screen. This attribut is not working with Scrollview.

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

<TextView  
    android:id="@+id/show_content"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:textColor="@color/black"
    android:textSize="25sp"
    android:gravity="center"
    android:padding="10dp" />

<LinearLayout
    android:id="@+id/hold_check_boxes"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_below="@+id/show_content" />

<Button android:id="@+id/save"            
    android:layout_width="150dp" 
    android:layout_height="wrap_content"         
    android:text="@string/save"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />   

</RelativeLayout>

any suggestions?

EDIT: with ScrollView

 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/mainScrollView"         
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" >            

    <RelativeLayout              
        android:id="@+id/topLayout"
        android:layout_width="fill_parent"             
        android:layout_height="wrap_content"
        android:orientation="vertical">                               

          <TextView  
            android:id="@+id/show_content"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:gravity="center"
            android:padding="10dp"
            android:background="@drawable/bottom_border" />

        <LinearLayout
            android:id="@+id/hold_check_boxes"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_below="@+id/show_content" />

        <Button android:id="@+id/save"            
            android:layout_width="150dp" 
            android:layout_height="wrap_content"         
            android:text="@string/save"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" />     

     </RelativeLayout>    
 </ScrollView> 
like image 678
Seb Avatar asked May 23 '12 08:05

Seb


1 Answers

You can do like this without taking as parent. The only thing you have to do is take Linearlayout in ScrollView.

<?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" >

    <TextView
        android:id="@+id/show_content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="@color/black"
        android:textSize="25sp" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/save"
        android:layout_below="@+id/show_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" >

        <LinearLayout
            android:id="@+id/hold_check_boxes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </ScrollView>

    <Button
        android:id="@+id/save"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/save" />

</RelativeLayout>

Update:

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <TextView
            android:id="@+id/show_content"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="10dp"
            android:textColor="@color/black"
            android:textSize="25sp" />

        <LinearLayout
            android:id="@+id/hold_check_boxes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/show_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="vertical" />

        <Button
            android:id="@+id/save"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/hold_check_boxes"
            android:layout_centerHorizontal="true"
            android:text="@string/save" />
    </RelativeLayout>

</ScrollView>
like image 111
Mohammed Azharuddin Shaikh Avatar answered Nov 15 '22 14:11

Mohammed Azharuddin Shaikh