Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a relative layout scrollable when it has many children views?

Tags:

my xml goes as shown below

    <?xml version="1.0" encoding="utf-8"?>     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/form_layout"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@color/black"     android:orientation="vertical"     android:overScrollMode="ifContentScrolls"     android:scrollbarStyle="insideOverlay"     android:scrollbars="vertical"  >       <Spinner         android:id="@+id/formulae"         android:layout_width="200dp"         android:layout_height="60dp"         android:layout_marginLeft="50dp"         android:layout_marginRight="50dp"         android:background="@color/LightSkyBlue"         android:dropDownWidth="wrap_content"         android:entries="@array/formulas"         android:gravity="center"         android:paddingLeft="0dp"         android:textAlignment="center" />        <EditText         android:id="@+id/k2_editText"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_above="@+id/al"         android:layout_alignRight="@+id/al_editText"         android:layout_alignTop="@+id/k2"         android:layout_marginLeft="120dp"         android:ems="10"         android:enabled="true"         android:inputType="numberDecimal"         android:onClick="@drawable/textfield_activated_holo_light"         android:textColor="@color/White"         android:textSize="15sp"         android:visibility="visible"         android:width="100dp" />      <TextView         android:id="@+id/k1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentLeft="true"         android:layout_below="@+id/dr"         android:layout_marginLeft="24dp"         android:layout_marginTop="28dp"         android:text="@string/K1"         android:textColor="@color/white"         android:textSize="25sp" />      <EditText         android:id="@+id/k1_editText"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_above="@+id/k2"         android:layout_alignLeft="@+id/k2_editText"         android:layout_alignRight="@+id/k2_editText"         android:layout_alignTop="@+id/k1"         android:background="@drawable/edit_text_holo_light"         android:ems="10"         android:enabled="true"         android:inputType="numberDecimal"         android:onClick="@drawable/textfield_activated_holo_light"         android:textColor="@color/White"         android:textSize="15sp"         android:visibility="visible"         android:width="100dp" />       <TextView         android:id="@+id/dr"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignLeft="@+id/formulae"         android:layout_below="@+id/formulae"         android:layout_marginTop="14dp"         android:layout_toLeftOf="@+id/k1_editText"         android:ems="10"         android:gravity="center"         android:text="@string/dr"         android:textColor="@color/White"         android:textSize="25sp" />        <TextView         android:id="@+id/k2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignRight="@+id/k1"         android:layout_below="@+id/k1"         android:layout_marginTop="38dp"         android:text="@string/K2"         android:textColor="@color/White"         android:textSize="25sp" />      <TextView         android:id="@+id/al"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignRight="@+id/k2"         android:layout_below="@+id/k2"         android:layout_marginTop="38dp"         android:text="@string/AL"         android:textColor="@color/White"         android:textSize="25sp" />      <EditText         android:id="@+id/al_editText"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignRight="@+id/formulae"         android:layout_alignTop="@+id/al"         android:layout_marginLeft="120dp"         android:ems="10"         android:enabled="true"         android:inputType="numberDecimal"         android:onClick="@drawable/textfield_activated_holo_light"         android:textColor="@color/White"         android:textSize="15sp"         android:visibility="visible"         android:width="100dp" />      <EditText         android:id="@+id/al_const_editText"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignBottom="@+id/al_const"         android:layout_alignRight="@+id/al_editText"         android:layout_marginLeft="120dp"         android:ems="10"         android:enabled="true"         android:inputType="numberDecimal"         android:onClick="@drawable/textfield_activated_holo_light"         android:textColor="@color/White"         android:textSize="15sp"         android:visibility="visible"         android:width="100dp" />      <EditText         android:id="@+id/dr_editText"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignLeft="@+id/k1_editText"         android:layout_alignRight="@+id/formulae"         android:layout_alignTop="@+id/dr"         android:ems="10"         android:inputType="numberDecimal|numberSigned"         android:textColor="@color/White"         android:textSize="15sp" >          <requestFocus />     </EditText>      <TextView         android:id="@+id/al_const"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignLeft="@+id/al"         android:layout_below="@+id/al_editText"         android:layout_marginTop="43dp"         android:text="@string/Rx"         android:textColor="@color/White"         android:textSize="20sp" />      <Button         android:id="@+id/result"         android:layout_width="match_parent"         android:layout_height="50dp"         android:layout_alignParentBottom="true"         android:layout_centerHorizontal="true"         android:background="@color/LightSkyBlue"         android:text="@string/Result"         android:textSize="25sp" />  </RelativeLayout> 

graphical layout : enter image description here


I want the fields from DR to A-const to be scrollable. I searched every possible solution in here and elsewhere but in vain. Being a beginner in android i seek help here

like image 922
human Avatar asked Jan 08 '13 07:01

human


People also ask

Which layout used to view group that displays children's views in relative positions?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).


2 Answers

Try 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="wrap_content" >      <ScrollView         android:layout_width="fill_parent"         android:layout_height="fill_parent" >          <RelativeLayout             android:id="@+id/form_layout"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:background="@color/black" >              <Spinner                 android:id="@+id/formulae"                 android:layout_width="200dp"                 android:layout_height="60dp"                 android:layout_marginLeft="50dp"                 android:layout_marginRight="50dp"                 android:background="@color/LightSkyBlue"                 android:dropDownWidth="wrap_content"                 android:entries="@array/formulas"                 android:gravity="center"                 android:paddingLeft="0dp"                 android:textAlignment="center" />              <EditText                 android:id="@+id/k2_editText"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_above="@+id/al"                 android:layout_alignRight="@+id/al_editText"                 android:layout_alignTop="@+id/k2"                 android:layout_marginLeft="120dp"                 android:ems="10"                 android:enabled="true"                 android:inputType="numberDecimal"                 android:onClick="@drawable/textfield_activated_holo_light"                 android:textColor="@color/White"                 android:textSize="15sp"                 android:visibility="visible"                 android:width="100dp" />              <TextView                 android:id="@+id/k1"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignParentLeft="true"                 android:layout_below="@+id/dr"                 android:layout_marginLeft="24dp"                 android:layout_marginTop="28dp"                 android:text="@string/K1"                 android:textColor="@color/white"                 android:textSize="25sp" />              <EditText                 android:id="@+id/k1_editText"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_above="@+id/k2"                 android:layout_alignLeft="@+id/k2_editText"                 android:layout_alignRight="@+id/k2_editText"                 android:layout_alignTop="@+id/k1"                 android:background="@drawable/edit_text_holo_light"                 android:ems="10"                 android:enabled="true"                 android:inputType="numberDecimal"                 android:onClick="@drawable/textfield_activated_holo_light"                 android:textColor="@color/White"                 android:textSize="15sp"                 android:visibility="visible"                 android:width="100dp" />              <TextView                 android:id="@+id/dr"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignLeft="@+id/formulae"                 android:layout_below="@+id/formulae"                 android:layout_marginTop="14dp"                 android:layout_toLeftOf="@+id/k1_editText"                 android:ems="10"                 android:gravity="center"                 android:text="@string/dr"                 android:textColor="@color/White"                 android:textSize="25sp" />              <TextView                 android:id="@+id/k2"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignRight="@+id/k1"                 android:layout_below="@+id/k1"                 android:layout_marginTop="38dp"                 android:text="@string/K2"                 android:textColor="@color/White"                 android:textSize="25sp" />              <TextView                 android:id="@+id/al"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignRight="@+id/k2"                 android:layout_below="@+id/k2"                 android:layout_marginTop="38dp"                 android:text="@string/AL"                 android:textColor="@color/White"                 android:textSize="25sp" />              <EditText                 android:id="@+id/al_editText"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignRight="@+id/formulae"                 android:layout_alignTop="@+id/al"                 android:layout_marginLeft="120dp"                 android:ems="10"                 android:enabled="true"                 android:inputType="numberDecimal"                 android:onClick="@drawable/textfield_activated_holo_light"                 android:textColor="@color/White"                 android:textSize="15sp"                 android:visibility="visible"                 android:width="100dp" />              <EditText                 android:id="@+id/al_const_editText"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignBottom="@+id/al_const"                 android:layout_alignRight="@+id/al_editText"                 android:layout_marginLeft="120dp"                 android:ems="10"                 android:enabled="true"                 android:inputType="numberDecimal"                 android:onClick="@drawable/textfield_activated_holo_light"                 android:textColor="@color/White"                 android:textSize="15sp"                 android:visibility="visible"                 android:width="100dp" />              <EditText                 android:id="@+id/dr_editText"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignLeft="@+id/k1_editText"                 android:layout_alignRight="@+id/formulae"                 android:layout_alignTop="@+id/dr"                 android:ems="10"                 android:inputType="numberDecimal|numberSigned"                 android:textColor="@color/White"                 android:textSize="15sp" >                  <requestFocus />             </EditText>              <TextView                 android:id="@+id/al_const"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignLeft="@+id/al"                 android:layout_below="@+id/al_editText"                 android:layout_marginTop="43dp"                 android:text="@string/Rx"                 android:textColor="@color/White"                 android:textSize="20sp" />              <Button                 android:id="@+id/result"                 android:layout_width="match_parent"                 android:layout_height="50dp"                 android:layout_alignParentBottom="true"                 android:layout_centerHorizontal="true"                 android:background="@color/LightSkyBlue"                 android:text="@string/Result"                 android:textSize="25sp" />         </RelativeLayout>     </ScrollView>  </RelativeLayout> 

Thanks.

like image 98
Pratik Sharma Avatar answered Sep 23 '22 15:09

Pratik Sharma


Try this...it works fine for me

    <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/form_layout"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:orientation="vertical"  android:overScrollMode="ifContentScrolls"  android:scrollbarStyle="insideOverlay"  android:scrollbars="vertical" >  <Spinner     android:id="@+id/formulae"     android:layout_width="200dp"     android:layout_height="60dp"     android:layout_marginLeft="50dp"     android:layout_marginRight="50dp"     android:dropDownWidth="wrap_content"     android:gravity="center"     android:paddingLeft="0dp" />  <ScrollView     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_above="@+id/result"     android:layout_below="@+id/formulae" >      <RelativeLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/formulae" >          <EditText             android:id="@+id/k2_editText"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_above="@+id/al"             android:layout_alignRight="@+id/al_editText"             android:layout_alignTop="@+id/k2"             android:layout_marginLeft="120dp"             android:ems="10"             android:enabled="true"             android:inputType="numberDecimal"             android:textSize="15sp"             android:visibility="visible"             android:width="100dp" />          <TextView             android:id="@+id/k1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignParentLeft="true"             android:layout_below="@+id/dr"             android:layout_marginLeft="24dp"             android:layout_marginTop="28dp"             android:text="K1"             android:textSize="25sp" />          <EditText             android:id="@+id/k1_editText"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_above="@+id/k2"             android:layout_alignLeft="@+id/k2_editText"             android:layout_alignRight="@+id/k2_editText"             android:layout_alignTop="@+id/k1"             android:ems="10"             android:enabled="true"             android:inputType="numberDecimal"             android:textSize="15sp"             android:visibility="visible"             android:width="100dp" />          <TextView             android:id="@+id/dr"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignLeft="@+id/formulae"             android:layout_below="@+id/formulae"             android:layout_marginTop="14dp"             android:layout_toLeftOf="@+id/k1_editText"             android:ems="10"             android:gravity="center"             android:text="dr"             android:textSize="25sp" />          <TextView             android:id="@+id/k2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignRight="@+id/k1"             android:layout_below="@+id/k1"             android:layout_marginTop="38dp"             android:text="K2"             android:textSize="25sp" />          <TextView             android:id="@+id/al"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignRight="@+id/k2"             android:layout_below="@+id/k2"             android:layout_marginTop="38dp"             android:text="AL"             android:textSize="25sp" />          <EditText             android:id="@+id/al_editText"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignRight="@+id/formulae"             android:layout_alignTop="@+id/al"             android:layout_marginLeft="120dp"             android:ems="10"             android:enabled="true"             android:inputType="numberDecimal"             android:textSize="15sp"             android:visibility="visible"             android:width="100dp" />          <EditText             android:id="@+id/al_const_editText"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignBottom="@+id/al_const"             android:layout_alignRight="@+id/al_editText"             android:layout_marginLeft="120dp"             android:ems="10"             android:enabled="true"             android:inputType="numberDecimal"             android:textSize="15sp"             android:visibility="visible"             android:width="100dp" />          <EditText             android:id="@+id/dr_editText"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignLeft="@+id/k1_editText"             android:layout_alignRight="@+id/formulae"             android:layout_alignTop="@+id/dr"             android:ems="10"             android:inputType="numberDecimal|numberSigned"             android:textSize="15sp" >              <requestFocus />         </EditText>          <TextView             android:id="@+id/al_const"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignLeft="@+id/al"             android:layout_below="@+id/al_editText"             android:layout_marginTop="43dp"             android:text="Rx"             android:textSize="20sp" />     </RelativeLayout> </ScrollView>  <Button     android:id="@+id/result"     android:layout_width="match_parent"     android:layout_height="50dp"     android:layout_alignParentBottom="true"     android:layout_centerHorizontal="true"     android:text="Result"     android:textSize="25sp" />  </RelativeLayout> 
like image 42
Ketan Ahir Avatar answered Sep 23 '22 15:09

Ketan Ahir