Hello everybody! I wanted to add all the elements in NestedScrollView so that with a small display you could scroll. When you add them there, the part is located at the top of the screen and they are superimposed on each other, and the part went outside the screen. I tried everything - it does not help. What should I do? Tell me please!

From NestedScrollView it looks like this:

With ScrollView

Without NestedScrollView: Without ScrollView

Xml markup code with NestedScrollView:

 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/content_record2" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.testprogram.alex.tram.RecordActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/SerialNumberAnimation" android:layout_above="@+id/RouteNumberAnimation" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/SerialNumberEdit" android:maxLength="4" android:singleLine="true" android:hint="@string/enter_sn" android:layout_marginBottom="23dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/SerialNumber" /> </ViewSwitcher> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/RouteNumberAnimation" android:layout_above="@+id/button" android:layout_centerHorizontal="true"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/RouteNumberEdit" android:hint="@string/enter_route" android:singleLine="true" android:layout_marginBottom="28dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/RouteNumber" /> </ViewSwitcher> <ViewSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusAnimation" android:layout_marginLeft="15dp" android:layout_marginStart="15dp" android:layout_alignTop="@+id/textView2" android:layout_toRightOf="@+id/textView2" android:layout_toEndOf="@+id/textView2" android:layout_alignBottom="@+id/textView2"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusIn" android:contentDescription="@string/plus_in_description" android:src="@drawable/plus1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusOut" android:contentDescription="@string/plus_out_description" android:src="@drawable/plus2" /> </ViewSwitcher> <ViewSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusAnimation" android:layout_marginRight="18dp" android:layout_marginEnd="18dp" android:layout_toLeftOf="@+id/textView2" android:layout_toStartOf="@+id/textView2" android:layout_marginBottom="75dp" android:layout_above="@+id/SerialNumberAnimation"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusIn" android:contentDescription="@string/minus_in_description" android:src="@drawable/minus1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusOut" android:contentDescription="@string/minus_out_description" android:src="@drawable/minus2" /> </ViewSwitcher> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fill_button_text" android:id="@+id/button" android:layout_alignParentBottom="true" android:layout_toLeftOf="@+id/textView2" android:layout_toStartOf="@+id/textView2" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/start_value_count" android:id="@+id/textView2" android:layout_alignBottom="@+id/MinusAnimation" android:layout_centerHorizontal="true" android:textSize="40sp" android:layout_alignTop="@+id/MinusAnimation" android:layout_alignParentBottom="false" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/end_button_text" android:id="@+id/button2" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/textView2" android:layout_toEndOf="@+id/textView2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Начало" android:id="@+id/button3" android:layout_below="@+id/textView2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="15dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FAIL" android:id="@+id/button4" android:layout_alignBottom="@+id/button3" android:layout_centerHorizontal="true" android:textColor="#ff0000" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="PASS" android:id="@+id/button5" android:layout_alignBottom="@+id/button4" android:layout_alignRight="@+id/SerialNumberAnimation" android:layout_alignEnd="@+id/SerialNumberAnimation" android:textColor="#001aff" /> </RelativeLayout> </android.support.v4.widget.NestedScrollView> 

Xml markup code without NestedScrollView:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.testprogram.alex.tram.MainActivity" tools:showIn="@layout/activity_record" android:orientation="vertical"> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/SerialNumberAnimation" android:layout_above="@+id/RouteNumberAnimation" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/SerialNumberEdit" android:maxLength="4" android:singleLine="true" android:hint="@string/enter_sn" android:layout_marginBottom="23dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/SerialNumber" /> </ViewSwitcher> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/RouteNumberAnimation" android:layout_above="@+id/button" android:layout_centerHorizontal="true"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/RouteNumberEdit" android:hint="@string/enter_route" android:singleLine="true" android:layout_marginBottom="28dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/RouteNumber" /> </ViewSwitcher> <ViewSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusAnimation" android:layout_marginLeft="15dp" android:layout_marginStart="15dp" android:layout_alignTop="@+id/textView2" android:layout_toRightOf="@+id/textView2" android:layout_toEndOf="@+id/textView2" android:layout_alignBottom="@+id/textView2"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusIn" android:contentDescription="@string/plus_in_description" android:src="@drawable/plus1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusOut" android:contentDescription="@string/plus_out_description" android:src="@drawable/plus2" /> </ViewSwitcher> <ViewSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusAnimation" android:layout_marginRight="18dp" android:layout_marginEnd="18dp" android:layout_toLeftOf="@+id/textView2" android:layout_toStartOf="@+id/textView2" android:layout_marginBottom="75dp" android:layout_above="@+id/SerialNumberAnimation"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusIn" android:contentDescription="@string/minus_in_description" android:src="@drawable/minus1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusOut" android:contentDescription="@string/minus_out_description" android:src="@drawable/minus2" /> </ViewSwitcher> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fill_button_text" android:id="@+id/button" android:layout_marginBottom="56dp" android:layout_alignParentBottom="true" android:layout_alignRight="@+id/MinusAnimation" android:layout_alignEnd="@+id/MinusAnimation" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/start_value_count" android:id="@+id/textView2" android:layout_alignBottom="@+id/MinusAnimation" android:layout_centerHorizontal="true" android:textSize="40sp" android:layout_alignTop="@+id/MinusAnimation" android:layout_alignParentBottom="false" android:layout_below="@+id/progressBarAnimation" /> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/progressBarAnimation" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_marginTop="50dp"> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/progressBar" android:theme="@style/BlueProgress" /> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/progressBar2" android:theme="@style/RedProgress" /> </ViewSwitcher> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/end_button_text" android:id="@+id/button2" android:layout_below="@+id/RouteNumberAnimation" android:layout_alignLeft="@+id/PlusAnimation" android:layout_alignStart="@+id/PlusAnimation" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Начало" android:id="@+id/button3" android:layout_below="@+id/textView2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="15dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FAIL" android:id="@+id/button4" android:layout_alignBottom="@+id/button3" android:layout_centerHorizontal="true" android:textColor="#ff0000" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="PASS" android:id="@+id/button5" android:layout_alignBottom="@+id/button4" android:layout_alignRight="@+id/SerialNumberAnimation" android:layout_alignEnd="@+id/SerialNumberAnimation" android:textColor="#001aff" /> </RelativeLayout> 
  • one
    Are you sure that you need a RelativeLayout and you cannot replace it with, for example, LinearLayout ? and try him to put the height in wrap_contetn - Yuriy SPb
  • @YuriSPb Changed to LinearLayout and the program writes this warning: Invalid layout param in a LinearLayout with the following parameters: alignParentBottom , alignRight , alignEnd , alignBottom , centerHorizontal , alignTop , below , alignParentLeft , alignParentStart , alignLeft , alignStart . Can I replace them with other parameters to align the elements? - HybridTC25 5:02 pm
  • one
    These attributes work only for RelativeLayout. When you go to LunearLayout, you need without them, rebuild your markup. You can use the wrapping of elements in containers, set dimensions through the "weight" - YuriiSPb
  • one
    The error suggests that only one child can be in ScrollView. And your markup is too big to figure it out right away. - Yuriy SPb
  • one
    @ ЮрийСПб Already wrote the answer. Good luck! Goodbye! - HybridTC25

1 answer 1

This issue was resolved by adding RelativeLayout content to LinearLayout . And in ScrollView added this LinearLayout . Where it was impossible to align, RelativeLayout used and the element was leveled.

Here is the new xml code:

 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/content_record2" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.testprogram.alex.tram.RecordActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.testprogram.alex.tram.MainActivity" tools:showIn="@layout/activity_record" android:orientation="vertical" android:measureWithLargestChild="false"> <RelativeLayout android:layout_width="match_parent" android:layout_height="64dp" android:orientation="horizontal" android:layout_marginTop="100dp"> <ViewSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusAnimation" android:layout_marginRight="15dp" android:layout_marginEnd="15dp" android:layout_toLeftOf="@+id/textView2" android:layout_toStartOf="@+id/textView2" android:layout_alignTop="@+id/textView2" android:layout_alignBottom="@+id/textView2"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusIn" android:contentDescription="@string/minus_in_description" android:src="@drawable/minus1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MinusOut" android:contentDescription="@string/minus_out_description" android:src="@drawable/minus2" /> </ViewSwitcher> <ViewSwitcher android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusAnimation" android:layout_marginLeft="15dp" android:layout_marginStart="15dp" android:layout_alignTop="@+id/textView2" android:layout_toRightOf="@+id/textView2" android:layout_toEndOf="@+id/textView2" android:layout_alignBottom="@+id/textView2"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusIn" android:contentDescription="@string/plus_in_description" android:src="@drawable/plus1" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/PlusOut" android:contentDescription="@string/plus_out_description" android:src="@drawable/plus2" /> </ViewSwitcher> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/start_value_count" android:id="@+id/textView2" android:textSize="40sp" android:layout_alignParentTop="false" android:layout_centerInParent="true" /> </RelativeLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Начало" android:id="@+id/button3" android:layout_marginTop="15dp" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="FAIL" android:id="@+id/button4" android:textColor="#ff0000" android:layout_gravity="center_horizontal" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="PASS" android:id="@+id/button5" android:textColor="#001aff" android:layout_gravity="right" /> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/SerialNumberAnimation"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/SerialNumberEdit" android:maxLength="4" android:singleLine="true" android:hint="@string/enter_sn" android:layout_marginBottom="23dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/SerialNumber" /> </ViewSwitcher> <ViewSwitcher android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/RouteNumberAnimation"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/RouteNumberEdit" android:hint="@string/enter_route" android:singleLine="true" android:layout_marginBottom="28dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="" android:id="@+id/RouteNumber" /> </ViewSwitcher> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/fill_button_text" android:id="@+id/button" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/end_button_text" android:id="@+id/button2" /> </LinearLayout> </android.support.v4.widget.NestedScrollView> 

Screenshot:

enter image description here

Thank you very much to the user @ YuriySPb for help!