Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set ScrollView as the parent of an RelativeLayout?

I am new to the android app development now i am designing an app,in that i have an activity which has two parallel edit text fields like shown in the image

enter image description here

(contains 15 sets of edit text fields). I used relative layout. I want to add a vertical scroll view because some text fields go out from the screen. I studied few tutorials and all of them use linear layouts to add scroll view.

Here is my layout.xml file

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

<EditText
   android:id="@+id/editText5"
    android:layout_width="85dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="100dp"
    android:layout_marginTop="5dp" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="85dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="200dp"
    android:layout_marginTop="5dp" />

<EditText
    android:id="@+id/EditText01"
    android:layout_width="85dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText5"
    android:layout_below="@+id/editText5"
    android:layout_marginTop="17dp" />

<EditText
    android:id="@+id/EditText02"
    android:layout_width="85dp"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/EditText01"
    android:layout_alignBottom="@+id/EditText01"
    android:layout_alignLeft="@+id/editText1" />

 </RelativeLayout>

Here how can I add scroll view without changing two parallel edit text fields. Please guide me. Thank you!

like image 253
Grant Avatar asked Nov 17 '25 14:11

Grant


1 Answers

Add a ScrollView as the root of your screen. ScrollView should have a single child layout that contains all the children..

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

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

        <!-- All your views -->

     </RelativeLayout>
</ScrollView>
like image 126
Ronnie Avatar answered Nov 19 '25 04:11

Ronnie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!