Adding a scroll view to an android layout

I have a relative layout in which I want to add scrollView, the problem is when I ever add a scroll view, all my relatively installed widgets have lost their places, I tried every opportunity, but I can’t set the scroll correctly, can anyone Anything to help me with this? I want to put a scroll view on all elements of an xml file.

NEW CODE:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" > <ImageButton android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="140dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_weight="0.9" android:background="@drawable/subscribe_second_top" android:orientation="vertical" > </ImageButton> <EditText android:id="@+id/editText1" android:layout_width="270dp" android:layout_height="wrap_content" android:layout_below="@+id/bebasNeueTextView1" android:layout_centerHorizontal="true" android:ems="10" android:inputType="textEmailAddress" /> <TextView android:id="@+id/bebasNeueTextView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:text="THE EMAIL YOU WILL USE TO GET ALL YOUR APPS CREATED BY THE SOFT" android:textColor="#000000" android:textSize="7sp" android:textStyle="bold" /> <TextView android:id="@+id/bebasNeueTextView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText2" android:layout_centerHorizontal="true" android:text="YOUR GOOGLE PLAY STORE ORDER NUMBER, IN ORDER TO PROVE YOU BOUG" android:textColor="#000000" android:textSize="7sp" android:textStyle="bold" /> <TextView android:id="@+id/bebasNeueTextView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/bebasNeueTextView2" android:layout_centerHorizontal="true" android:layout_marginTop="16dp" android:text="ENTER YOUR PLAY STORE ORDER NUMBER" android:textColor="#94c23e" android:textSize="13sp" android:textStyle="bold" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:background="@drawable/subscribe_second_bottom" android:paddingBottom="5dp" android:paddingTop="30dp" > <com.apkcreator.fwd.BebasNeueButton android:id="@+id/finishButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="#94c23e" android:paddingBottom="10dp" android:paddingLeft="30dp" android:paddingRight="30dp" android:paddingTop="10dp" android:text="FINISH" android:textSize="18sp" android:textStyle="bold" /> </RelativeLayout> <TextView android:id="@+id/bebasNeueTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="170dp" android:text="ENTER YOUR EMAIL" android:textColor="#94c23e" android:textSize="13sp" android:textStyle="bold" /> <EditText android:id="@+id/editText2" android:layout_width="270dp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_below="@+id/bebasNeueTextView4" android:ems="10" android:layout_centerHorizontal="true"> </EditText> </RelativeLayout> </ScrollView> 
+6
source share
6 answers

Check out this link: How do I add a scrollbar to a relative layout?

Your problem may be related to the viewport, android:fillViewport="true" in ScrollLayout should solve your problem.

Viewing xml, you can install this file using the vertical LinearLayout, which is much simpler for this use case.

By the way, I advise you to avoid scroll bars on user inputs, such as registration, login ... Your form contains only 2 fields, I'm sure that you can organize its display on the screen immediately (much better than UX!),

+4
source

Just change the start of your xml code to:

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" > 
+5
source
 <LinearLayout> <ScrollView> <RelativeLayout> <put your all UI component here /> </RelativeLayout> </ScrollView> </LinearLayout> 
+1
source

This is because the height of the RelativeLayout setting for match_parent inside ScrollView makes no sense. Try using the fillViewport property for ScrolView. Add this line to your ScrollView element:

 android:fillViewport="true" 

I have not tried this myself. Maybe this will help you. For more information, see the official documentation here .

+1
source

set items using

 androd:margintTop="+5dp\-5dp" 

means + or - value on all sides as necessary

0
source

Please check out the code below, this may help. Reorder the items as you want, and before using any properties of any item, please read it.

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ffffff" > <ImageButton android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="140dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="5dp" android:layout_weight="0.9" android:background="@drawable/ic_launcher" android:orientation="vertical" > </ImageButton> <EditText android:id="@+id/editText1" android:layout_width="270dp" android:layout_height="wrap_content" android:layout_below="@+id/linearLayout1" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:ems="10" android:inputType="textEmailAddress" /> <TextView android:id="@+id/bebasNeueTextView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:text="THE EMAIL YOU WILL USE TO GET ALL YOUR APPS CREATED BY THE SOFT" android:textColor="#000000" android:textSize="7sp" android:textStyle="bold" /> <TextView android:id="@+id/bebasNeueTextView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/bebasNeueTextView2" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:text="YOUR GOOGLE PLAY STORE ORDER NUMBER, IN ORDER TO PROVE YOU BOUG" android:textColor="#000000" android:textSize="7sp" android:textStyle="bold" /> <TextView android:id="@+id/bebasNeueTextView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/bebasNeueTextView6" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:text="ENTER YOUR PLAY STORE ORDER NUMBER" android:textColor="#94c23e" android:textSize="13sp" android:textStyle="bold" /> <TextView android:id="@+id/bebasNeueTextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/bebasNeueTextView4" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:text="ENTER YOUR EMAIL" android:textColor="#94c23e" android:textSize="13sp" android:textStyle="bold" /> <EditText android:id="@+id/editText2" android:layout_width="270dp" android:layout_height="wrap_content" android:layout_below="@+id/bebasNeueTextView1" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:ems="10" > </EditText> <RelativeLayout android:layout_width="fill_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:layout_below="@+id/editText2" android:layout_marginTop="5dp" android:paddingBottom="5dp" > <com.apkcreator.fwd.BebasNeueButton android:id="@+id/finishButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="#94c23e" android:paddingBottom="10dp" android:paddingLeft="30dp" android:paddingRight="30dp" android:paddingTop="10dp" android:text="FINISH" android:textSize="18sp" android:textStyle="bold" /> </RelativeLayout> </RelativeLayout> </ScrollView> 
-1
source

Source: https://habr.com/ru/post/956054/


All Articles