Android is it possible to have a part of the layout scrollable - android

I am trying to make an android application and I need the middle part of my screen to be scrollable. When I set a ScrollView inside an Relative Layout my application crashes.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backgroundcolor"
android:orientation="vertical">
<TextView
android:id="#+id/tvCijferHalen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignParentEnd="true"
android:layout_alignStart="#+id/etWegingTehalenCijfer"
android:layout_alignTop="#+id/textView"
android:layout_marginEnd="26dp"
android:layout_marginStart="20dp"
android:background="?android:attr/colorPressedHighlight"
android:paddingStart="65dp"
android:paddingTop="15dp"
android:text="0"
android:textColor="?attr/editTextColor"
android:textSize="30dp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/etWatStaan"
android:layout_alignEnd="#+id/etWatStaan"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="328dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:background="#android:color/holo_green_light"
android:paddingStart="65dp"
android:paddingTop="15dp"
android:text="0"
android:textColor="?attr/editTextColor"
android:textSize="30dp" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/tvCijferHalen"
android:layout_above="#+id/etWatStaan"
android:layout_alignStart="#+id/textView"
android:layout_alignEnd="#+id/tvCijferHalen">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:background="#color/backgroundcolor"
android:orientation="vertical">
<EditText
android:id="#+id/etcijfer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="185dp"
android:layout_marginTop="46dp"
android:ems="10"
android:hint="Cijfer 1"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="visible" />
<EditText
android:id="#+id/etweging1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/etcijfer1"
android:layout_alignBottom="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_marginEnd="28dp"
android:layout_marginRight="46dp"
android:layout_marginStart="187dp"
android:layout_toStartOf="#+id/bLess1"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="visible" />
<Button
android:id="#+id/bLess1"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging1"
android:layout_alignParentEnd="true" />
<EditText
android:id="#+id/etcijfer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_below="#+id/etcijfer1"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Cijfer 2"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<EditText
android:id="#+id/etweging2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etweging1"
android:layout_alignStart="#+id/etweging1"
android:layout_below="#+id/etweging1"
android:layout_marginTop="10dp"
android:layout_toStartOf="#+id/bLess2"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<Button
android:id="#+id/bLess2"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging2"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
<EditText
android:id="#+id/etcijfer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_below="#+id/etcijfer2"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Cijfer 3"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<EditText
android:id="#+id/etweging3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etweging1"
android:layout_alignStart="#+id/etweging1"
android:layout_below="#+id/etweging2"
android:layout_marginTop="10dp"
android:layout_toStartOf="#+id/bLess2"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<Button
android:id="#+id/bLess3"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging3"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
<EditText
android:id="#+id/etcijfer4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_below="#+id/etcijfer3"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Cijfer 4"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<EditText
android:id="#+id/etweging4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etweging1"
android:layout_alignStart="#+id/etweging1"
android:layout_below="#+id/etweging3"
android:layout_marginTop="10dp"
android:layout_toStartOf="#+id/bLess3"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<Button
android:id="#+id/bLess4"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging4"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
<EditText
android:id="#+id/etcijfer5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_below="#+id/etcijfer4"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Cijfer 5"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<EditText
android:id="#+id/etweging5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etweging1"
android:layout_alignStart="#+id/etweging1"
android:layout_below="#+id/etweging4"
android:layout_marginTop="10dp"
android:layout_toStartOf="#+id/bLess4"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<Button
android:id="#+id/bLess5"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging5"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
<EditText
android:id="#+id/etcijfer6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_below="#+id/etcijfer5"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Cijfer 6"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<EditText
android:id="#+id/etweging6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etweging1"
android:layout_alignStart="#+id/etweging1"
android:layout_below="#+id/etweging5"
android:layout_marginTop="10dp"
android:layout_toStartOf="#+id/bLess5"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<Button
android:id="#+id/bLess6"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging6"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
<EditText
android:id="#+id/etcijfer7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etcijfer1"
android:layout_alignParentStart="true"
android:layout_below="#+id/etcijfer6"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Cijfer 7"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<EditText
android:id="#+id/etweging7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/etweging1"
android:layout_alignStart="#+id/etweging1"
android:layout_below="#+id/etweging6"
android:layout_marginTop="10dp"
android:layout_toStartOf="#+id/bLess6"
android:ems="10"
android:hint="weging"
android:inputType="numberDecimal"
android:text="1"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:visibility="gone" />
<Button
android:id="#+id/bLess7"
android:layout_width="30dp"
android:layout_height="40dp"
android:background="#android:color/transparent"
android:drawableLeft="#android:drawable/ic_delete"
android:text="Button"
android:layout_alignTop="#+id/etweging7"
android:layout_alignParentEnd="true"
android:visibility="gone"/>
</RelativeLayout>
</ScrollView>
<EditText
android:id="#+id/etWatStaan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bNiewCijfer"
android:layout_alignEnd="#+id/etWegingTehalenCijfer"
android:layout_alignParentStart="true"
android:layout_marginEnd="200dp"
android:layout_marginRight="48dp"
android:ems="10"
android:hint="Wat wil je staan"
android:inputType="numberDecimal"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray" />
<EditText
android:id="#+id/etWegingTehalenCijfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:ems="10"
android:hint="weging"
android:inputType="number"
android:textColor="#android:color/black"
android:textColorHint="#android:color/darker_gray"
android:layout_alignBaseline="#+id/etWatStaan"
android:layout_alignBottom="#+id/etWatStaan"
android:layout_alignParentStart="true"
android:layout_marginStart="187dp" />
<Button
android:id="#+id/bNiewCijfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:text="Cijfer Toevoegen"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView7"
android:layout_alignBottom="#+id/textView7"
android:layout_alignEnd="#+id/tvCijferHalen"
android:layout_alignStart="#+id/tvCijferHalen"
android:background="?android:attr/colorMultiSelectHighlight"
android:text="Te halen Cijfer"
android:textAlignment="center"
android:textColor="?attr/editTextColor" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/textView"
android:layout_marginTop="13dp"
android:background="#android:color/holo_green_dark"
android:text="Gemiddelde"
android:textAlignment="center"
android:textColor="?attr/editTextColor" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView9"
android:layout_alignBottom="#+id/textView9"
android:layout_alignEnd="#+id/ScrollView01"
android:layout_alignStart="#+id/tvCijferHalen"
android:layout_marginEnd="71dp"
android:text="Weging"
android:textAlignment="center"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView"
android:layout_alignStart="#+id/ScrollView01"
android:layout_alignTop="#+id/ScrollView01"
android:layout_marginTop="31dp"
android:text="Cijfer"
android:textAlignment="center"
android:textColor="#android:color/black" />
Can someone help me ? I am wondering if it's even possible to have only a part of the screen scrollable

Try this approach:
Step 1
Use a LinearLayout as your root element to enable you to use layout_weightattribute;
Step 2
Inside your layout, you can split it into 3 parts each with a layout_weight of .3
For example:
<LinearLayout
...
orientation="vertical"
... >
<LinearLayout
layout_weight=".3"
layout_width="match_parent"
layout_height="0dp" />
<ScrollView
layout_weight=".3"
layout_width="match_parent"
layout_height="0dp" />
<LinearLayout
layout_weight=".3"
layout_width="match_parent"
layout_height="0dp" />
</LinearLayout> !-- end of root layout here
I said .3 just in case you want to have the sections occupy the same size of the window; but you can set them to whatever you want according to your needs.
I hope this helps.
Note A ScrollView only accepts ONE child element!
Good luck!

Related

handle views of relative layout on screen rotation

My views get messed up on screen rotation. The data I enter in edit-text does not get erased.
How could I handle my views on screen rotation?
without rotation
with rotation
My code:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="com.example.juhi_gupta.pizza_corner.Home_Delivery_Activity">
<TextView
android:id="#+id/home_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:text="Home Page"
android:textAllCaps="true"
android:textColor="#32127A"
android:textSize="30sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/home_page"
android:layout_marginLeft="26dp"
android:layout_marginStart="26dp"
android:layout_marginTop="33dp"
android:text="Name :"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/name"
android:layout_alignBottom="#+id/name"
android:layout_alignEnd="#+id/option_3"
android:layout_alignRight="#+id/option_3"
android:layout_marginTop="33dp"
android:ems="10"
android:hint="enter full name"
android:inputType="textCapWords"
android:textColor="#228B22" />
<TextView
android:id="#+id/items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_below="#+id/editText"
android:layout_marginTop="33dp"
android:text="#string/delivery_items"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/items"
android:layout_alignRight="#+id/items"
android:layout_below="#+id/items"
android:layout_marginTop="14dp"
android:text="#string/cheeze_burst"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/option_7"
android:layout_marginLeft="15dp"
android:layout_marginTop="-1dp"
android:layout_toRightOf="#+id/mobile"
android:text="#string/mexican_wave"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/option_2"
android:layout_alignBottom="#+id/option_2"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="0dp"
android:layout_toEndOf="#+id/option_2"
android:layout_toRightOf="#+id/option_2"
android:text="#string/extravaganja"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/option_3"
android:layout_alignLeft="#+id/option_1"
android:layout_marginTop="5dp"
android:text="#string/capsicum_twist"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/option_4"
android:layout_alignRight="#+id/editText7"
android:layout_marginTop="2dp"
android:layout_marginRight="-12dp"
android:text="#string/choriza_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/option_4"
android:layout_marginLeft="24dp"
android:layout_marginTop="-3dp"
android:layout_toRightOf="#+id/mobile"
android:text="#string/golden_corn"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/rate"
android:layout_alignTop="#+id/items"
android:layout_marginLeft="7dp"
android:layout_marginTop="0dp"
android:text="#string/paneer_crisp"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/option_7"
android:layout_marginLeft="14dp"
android:layout_marginTop="-1dp"
android:layout_toRightOf="#+id/Sumit"
android:text="#string/pineapple_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:layout_toLeftOf="#+id/home_page"
android:text="#string/quantity"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/quantity"
android:layout_alignBottom="#+id/quantity"
android:layout_alignLeft="#+id/editText"
android:layout_alignStart="#+id/editText"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:layout_marginTop="33dp"
android:ems="5"
android:hint="#string/_1_to_1000"
android:inputType="number"
android:textColor="#228B22" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/quantity"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="20dp"
android:layout_toStartOf="#+id/home_page"
android:layout_toLeftOf="#+id/home_page"
android:text="#string/address"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/address"
android:layout_marginLeft="23dp"
android:layout_marginTop="-10dp"
android:layout_toRightOf="#+id/option_1"
android:ems="10"
android:hint="#string/enter_full_address"
android:textColor="#228B22" />
<TextView
android:id="#+id/mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/date"
android:layout_alignBottom="#+id/editText4"
android:layout_marginBottom="12dp"
android:text="#string/mobile_number"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/editText3"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="171dp"
android:ems="10"
android:hint="#string/_10_digit_mobile_number"
android:inputType="number"
android:textColor="#228B22" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_alignTop="#+id/editText4"
android:layout_marginLeft="2dp"
android:layout_marginTop="54dp"
android:text="#string/delivery_date"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/editText4"
android:layout_alignLeft="#+id/editText4"
android:layout_alignBottom="#+id/date"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="33dp"
android:layout_marginBottom="-18dp"
android:ems="2"
android:hint="#string/dd"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText6"
android:layout_alignBottom="#+id/editText6"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="-43dp"
android:layout_toEndOf="#+id/editText2"
android:layout_toRightOf="#+id/editText2"
android:ems="4"
android:hint="#string/yyyy"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_marginEnd="-2dp"
android:layout_marginRight="-2dp"
android:layout_marginBottom="-40dp"
android:layout_toStartOf="#+id/rate"
android:layout_toLeftOf="#+id/rate"
android:ems="2"
android:hint="#string/mm"
android:inputType="date"
android:textColor="#228B22" />
<TextView
android:id="#+id/emailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/emailText"
android:layout_alignLeft="#+id/quantity"
android:layout_marginLeft="0dp"
android:text="#string/email_id"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/emailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText5"
android:layout_alignRight="#+id/option_5"
android:layout_marginTop="20dp"
android:layout_marginRight="24dp"
android:ems="10"
android:hint="#string/abc_gmail_com"
android:textColor="#228B22" />
<Button
android:id="#+id/Sumit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Cancel"
android:layout_alignBottom="#+id/Cancel"
android:layout_marginTop="33dp"
android:layout_toLeftOf="#+id/option_2"
android:layout_toStartOf="#+id/option_2"
android:background="#ffff00"
android:onClick="open"
android:text="#string/sumit"
android:textStyle="bold" />
<Button
android:id="#+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/option_6"
android:layout_alignParentBottom="true"
android:layout_marginRight="19dp"
android:layout_marginBottom="12dp"
android:background="#ffff00"
android:onClick="reset_all_input_parameters"
android:text="#string/cancel"
android:textStyle="bold" />
<Button
android:id="#+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Cancel"
android:layout_alignBottom="#+id/Cancel"
android:layout_marginStart="6dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="33dp"
android:layout_marginBottom="1dp"
android:layout_toEndOf="#+id/option_2"
android:layout_toRightOf="#+id/option_2"
android:background="#ffff00"
android:onClick="rate_page"
android:text="#string/rate_us"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
I don't want to fix the orientation of my app. i.e.:-
setRequestedOrientation ( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ) ; or
android:configChanges= " keyboard|keyboardHidden|orientation"
Only use two layouts for each screen orientation in case you really need a different layout for both cases. I suppose that in your case is much better to have one layout that adjust to both cases.
When working with layout, consider using ConstraintLayout because it adjusts for all screen sizes and cases. Trust me, when I was using RelativeLayout and I was laze to learn about ConstraintLayout, I was being dumb because with ConstraintLayout you will gain a lot of time. Imagine coding one layout that will adjust to more than 20 screens.
For your case, you can use this code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<TextView
android:id="#+id/home_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:text="#string/home_page"
android:textAllCaps="true"
android:textColor="#32127A"
android:textSize="30sp"
android:textStyle="bold|italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Name :"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/home_page" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:ems="10"
android:hint="enter full name"
android:inputType="textCapWords"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/name"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/delivery_items"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/name"
app:layout_constraintTop_toBottomOf="#+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"/>
<LinearLayout
android:id="#+id/radioGroupLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintStart_toStartOf="#+id/items"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/items"
app:layout_constraintHorizontal_bias="0.0">
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioButton
android:id="#+id/option_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cheeze_burst"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mexican_wave"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/extravaganja"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/capsicum_twist"
android:textColor="#32127A"
android:textStyle="bold" />
</RadioGroup>
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioButton
android:id="#+id/option_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choriza_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/golden_corn"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/paneer_crisp"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pineapple_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
</RadioGroup>
</LinearLayout>
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:text="#string/quantity"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/radioGroupLinearLayout"
app:layout_constraintStart_toStartOf="parent"/>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:ems="5"
android:hint="#string/_1_to_1000"
android:inputType="number"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/quantity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/quantity"
app:layout_constraintBottom_toBottomOf="#+id/quantity"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/quantity"
android:layout_marginTop="20dp"
android:text="#string/address"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/quantity"
app:layout_constraintStart_toStartOf="#+id/quantity" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:ems="10"
android:hint="#string/enter_full_address"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/address"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/address"
app:layout_constraintBottom_toBottomOf="#+id/address"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/mobile_number"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/address"
app:layout_constraintStart_toStartOf="#+id/address"/>
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="#string/_10_digit_mobile_number"
android:inputType="number"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/mobile"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/mobile"
app:layout_constraintBottom_toBottomOf="#+id/mobile"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/delivery_date"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/mobile"
app:layout_constraintStart_toStartOf="#+id/mobile"/>
<LinearLayout
android:id="#+id/dateLinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:orientation="horizontal"
app:layout_constraintStart_toEndOf="#+id/date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/date"
app:layout_constraintBottom_toBottomOf="#+id/date"
app:layout_constraintHorizontal_bias="0.0">
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="2"
android:hint="#string/dd"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:hint="#string/yyyy"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="2"
android:hint="#string/mm"
android:inputType="date"
android:textColor="#228B22" />
</LinearLayout>
<TextView
android:id="#+id/emailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/email_id"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/date"
app:layout_constraintStart_toStartOf="#+id/date"/>
<EditText
android:id="#+id/emailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="#string/abc_gmail_com"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/emailTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/emailTextView"
app:layout_constraintBottom_toBottomOf="#+id/emailTextView"
app:layout_constraintHorizontal_bias="0.0"/>
<Button
android:id="#+id/Sumit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="#ffff00"
android:onClick="open"
android:text="#string/sumit"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#+id/Cancel"
app:layout_constraintTop_toBottomOf="#+id/emailTextView"
app:layout_constraintBottom_toBottomOf="parent"/>
<Button
android:id="#+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:onClick="reset_all_input_parameters"
android:text="#string/cancel"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/Sumit"
app:layout_constraintTop_toTopOf="#+id/Sumit"
app:layout_constraintBottom_toBottomOf="#+id/Sumit"
app:layout_constraintEnd_toStartOf="#+id/rate"/>
<Button
android:id="#+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:onClick="rate_page"
android:text="#string/rate_us"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/Cancel"
app:layout_constraintTop_toTopOf="#+id/Cancel"
app:layout_constraintBottom_toBottomOf="#+id/Cancel"
app:layout_constraintEnd_toEndOf="parent"/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
You can create another view for the same page in the editor. In the upper settings, choose orientation and create one for horizontal orientation. Set everything as you wish and you app will use the version you created when the orientation changes.
In orientation changes everything is rendered again in Android. However, as far as I know, you should now lose the EditText entries. If your TextViews are also set correctly in vertical mode, after setting up horizontal mode, they should also appear as expected.
A simple way to obtain a landscape layout is creating a layout-land resource directory folder.
Right click on
Res folder >> New >> AndroidResoursceDirectory
A dialogue box appears in that select Resource type as layout from the drop-down and select orientation from qualifiers and add landscape and click ok. Hence a folder will create under the res folder "layout-land".
Copy your current layout and paste in the layout-land folder and then edit your layout as per how you want to display it while orientation changes to the landscape mode.
By this method when you shift your app orientation from portrait to landscape you can create the same view designed for landscape mode.

RelativeLayout inside ScrollView won't scroll

<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView style="#style/ccccc"
android:layout_height="match_parent"
android:layout_width="match_parent">
<RelativeLayout
android:id="#+id/activity_move"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#fdf1dc"
android:orientation="vertical"
android:scrollbars="vertical" >
<TextView
android:text="Create Your Monster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#6D0000"
android:textAlignment="center"
android:textAllCaps="false"
android:fontFamily="serif"
android:textStyle="normal|bold"
android:textSize="24sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/nameTextBox"
android:textAlignment="center"
android:textColor="#6D0000"
android:fontFamily="serif"
android:typeface="sans"
android:textSize="14sp"
android:text="Enter Name..."
android:layout_marginTop="38dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:text="NAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:textAlignment="center"
android:textStyle="normal|bold"
android:fontFamily="serif"
android:textColor="#6D0000"
android:textSize="18sp"
android:layout_alignBaseline="#+id/nameTextBox"
android:layout_alignBottom="#+id/nameTextBox"
android:layout_toLeftOf="#+id/nameTextBox"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_menu_upload"
android:id="#+id/imageButton"
android:elevation="0dp"
style="#android:style/Widget.Holo.Light.ImageButton"
android:layout_below="#+id/nameTextBox"
android:layout_alignRight="#+id/editText3"
android:layout_alignEnd="#+id/editText3" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editText3"
android:text="STR"
android:textAlignment="center"
android:textColor="#6D0000"
android:textSize="14sp"
android:fontFamily="serif"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editText5"
android:textColor="#6D0000"
android:textSize="14sp"
android:fontFamily="serif"
android:text="CON"
android:textAlignment="center"
android:layout_below="#+id/editText3"
android:layout_alignLeft="#+id/editText3"
android:layout_alignStart="#+id/editText3" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editText6"
android:textSize="14sp"
android:fontFamily="serif"
android:textColor="#6D0000"
android:text="INT"
android:textAlignment="center"
android:layout_below="#+id/editText5"
android:layout_alignLeft="#+id/editText5"
android:layout_alignStart="#+id/editText5" />
<TextView
android:text="STATS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:textColor="#6D0000"
android:textSize="18sp"
android:fontFamily="serif"
android:textStyle="normal|bold"
android:textAlignment="center"
android:layout_marginBottom="13dp"
android:layout_above="#+id/editText3"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:layout_below="#+id/editText6"
android:layout_centerHorizontal="true"
android:id="#+id/editText"
android:textSize="14sp"
android:fontFamily="serif"
android:textColor="#6D0000"
android:textAlignment="center"
android:text="DEX" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true"
android:id="#+id/editText2"
android:textSize="14sp"
android:textColor="#6D0000"
android:fontFamily="serif"
android:text="WIS"
android:textAlignment="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:layout_below="#+id/editText2"
android:layout_alignLeft="#+id/editText2"
android:layout_alignStart="#+id/editText2"
android:id="#+id/editText4"
android:textSize="14sp"
android:textColor="#6D0000"
android:textAlignment="center"
android:text="CHA"
android:fontFamily="serif" />
<TextView
android:text="IMAGE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton"
android:layout_marginBottom="14dp"
android:id="#+id/textView2"
android:layout_toLeftOf="#+id/nameTextBox"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center"
android:textStyle="normal|bold"
android:textColor="#6D0000"
android:textSize="18sp"
android:fontFamily="serif" />
<TextView
android:text="LANGUAGES"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="55dp"
android:id="#+id/textView7"
android:textColor="#6D0000"
android:fontFamily="serif"
android:textSize="18sp"
android:textStyle="normal|bold"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView7"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:id="#+id/LanguageSpinner1"
android:entries="#array/langList"
android:prompt="#string/langPrompt"/>
<TextView
android:text="First Language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:textColor="#6D0000"
android:textAlignment="center"
android:fontFamily="serif"
android:textSize="16sp"
android:layout_below="#+id/textView7"
android:layout_alignLeft="#+id/textView7"
android:layout_alignStart="#+id/textView7"
android:layout_marginTop="24dp"
android:layout_alignRight="#+id/textView7"
android:layout_alignEnd="#+id/textView7" />
<TextView
android:text="Second Language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView9"
android:textColor="#6D0000"
android:textAlignment="center"
android:textSize="16sp"
android:fontFamily="serif"
android:layout_below="#+id/LanguageSpinner1"
android:layout_centerHorizontal="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
android:layout_below="#+id/textView9"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:entries="#array/langList" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Could anyone help me find the reason as to why this won't scroll? Inside the relative layout I have textViews, spinners and editTexts. I'm pretty new to android and xml so I have no idea why it's not scrolling.
Edit: here is the full layout as requested.
Based on your code you don't need the parent linear layout. Try to delete it and use the scrollView as parent. And also remove the orientation and scrollbars attributes to the relativeLayout, you don't need them.

Android SDK: RelativeLayout - Button WILL NOT center horizontally, even with Layout_CenterHorizontal=true

I really hope somebody can help me here because I am going to start pulling my hair out if this keeps doing what it's doing.
I'm trying to design a layout and I want all of my stuff to be centered. So far, everything is. However, the Save button I created will not center itself for the life of it. It consistently aligns its left edge with the center of the screen, rather than the center of the button itself.
Below is a screenshot of my simple design and the xml behind it... Any help will be GREATLY appreciated!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_settings"
tools:context="com.hypertom.weeklymealgenerator.SettingsActivity"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/strSettingsTitle"
android:id="#+id/textView"
android:textIsSelectable="false"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/textView2" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsNumMeals"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginTop="40dp"
android:layout_marginLeft="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsThresholdMin"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_alignEnd="#+id/textView2"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsThresholdMax"
android:id="#+id/textView4"
android:layout_below="#+id/textView3"
android:layout_alignEnd="#+id/textView3"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsNumServings"
android:id="#+id/textView5"
android:layout_below="#+id/textView4"
android:layout_alignEnd="#+id/textView4"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsNumSubstitutes"
android:id="#+id/textView6"
android:layout_below="#+id/textView5"
android:layout_alignEnd="#+id/textView5"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnSettingsSave"
android:id="#+id/button4"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="200dp" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText"
android:layout_alignBottom="#+id/textView2"
android:layout_toEndOf="#+id/textView2"
android:layout_marginBottom="-12dp"
android:textSize="18sp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText2"
android:layout_alignBottom="#+id/textView3"
android:layout_alignStart="#+id/editText"
android:textSize="18sp"
android:layout_marginBottom="-12dp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText3"
android:layout_above="#+id/textView5"
android:layout_alignStart="#+id/editText2"
android:layout_marginBottom="-12dp"
android:textSize="18sp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText4"
android:layout_above="#+id/textView6"
android:layout_alignStart="#+id/editText3"
android:textSize="18sp"
android:layout_marginBottom="-12dp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText5"
android:layout_alignBottom="#+id/textView6"
android:layout_alignStart="#+id/editText4"
android:layout_marginBottom="-12dp"
android:textSize="18sp"
android:gravity="center" />
</RelativeLayout>
Something like this ? It can be done much easier in LinearLayout though.
<RelativeLayout 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">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="strSettingsTitle"
android:layout_marginTop="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textIsSelectable="false"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:id="#+id/linearlayout">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="10dp"
android:layout_centerInParent="true">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="# of Meals"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/textView2"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="Threshold Min"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/textView3"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="Threshold Max"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/textView4"
android:gravity="right"
android:layout_marginTop="10dp"
android:text="Num of Servings"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="30dp"
android:layout_below="#+id/textView5"
android:layout_marginTop="10dp"
android:text="Num of Substitutes"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="10dp">
<EditText
android:id="#+id/editText"
android:layout_width="65dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText2"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/editText"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText3"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_below="#+id/editText2"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText4"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_below="#+id/editText3"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText5"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_below="#+id/editText4"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_centerInParent="true"
android:layout_below="#+id/linearlayout"
android:text="Save" />
</RelativeLayout>

android scrollable activity layout

I am trying to make my activity screen where there is a form to be filled scrollable but unfortunately, when I tried it crashed the app. I have the following xml for that activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textDirection="anyRtl"
tools:context=".AddDiscountActivity" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="19dp"
android:text="#string/discountLocationLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/shopLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignRight="#+id/shopCity"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView5"
android:layout_below="#+id/shopDiscount"
android:layout_marginTop="21dp"
android:text="#string/discountDurationLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/shopDiscountDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView6"
android:layout_alignLeft="#+id/shopDiscount"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/shopDiscount"
android:layout_alignParentRight="true"
android:text="#string/discountRateLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:background="#drawable/roundbutton"
android:text="#string/discountPublishButtonLabel"
android:textColor="#color/white"
android:onClick="SubmitData"
android:width="250dp" />
<EditText
android:id="#+id/shopCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/shopName"
android:ems="10"
android:inputType="text" >
</EditText>
<EditText
android:id="#+id/shopDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/shopLocation"
android:layout_below="#+id/shopLocation"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="number" />
<EditText
android:id="#+id/shopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:ems="10"
android:inputType="text">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/categoriesSpinner"
android:layout_alignRight="#+id/textView2"
android:text="#string/discountCategoryLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<Spinner
android:id="#+id/categoriesSpinner"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_above="#+id/shopName"
android:layout_alignLeft="#+id/button1"
android:layout_marginBottom="16dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView2"
android:layout_marginTop="206dp"
android:text="#string/discountCityLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/shopCity"
android:layout_alignLeft="#+id/textView5"
android:layout_marginBottom="18dp"
android:text="#string/discountShopLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView1"
android:layout_marginTop="14dp"
android:gravity="right"
android:text="#string/addDiscountMsg"
android:textAlignment="viewEnd"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textDirection="anyRtl" />
</RelativeLayout>
And when I tried to add the following after defining RelativeLayout and before closing RelativeLayout, it broke the app immediately when I run it.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
...........
</ScrollView>
How can I make it scrollable?
Your app crashes because ScrollView can host only one direct child.
Direct from official documentation:
Layout container for a view hierarchy that can be scrolled by the
user, allowing it to be larger than the physical display. A ScrollView
is a FrameLayout, meaning you should place one child in it containing
the entire contents to scroll; this child may itself be a layout
manager with a complex hierarchy of objects. A child that is often
used is a LinearLayout in a vertical orientation, presenting a
vertical array of top-level items that the user can scroll through.
Look this http://developer.android.com/reference/android/widget/ScrollView.html.
To solve your xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textDirection="anyRtl"
tools:context=".AddDiscountActivity" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="19dp"
android:text="#string/discountLocationLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/shopLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignRight="#+id/shopCity"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView5"
android:layout_below="#+id/shopDiscount"
android:layout_marginTop="21dp"
android:text="#string/discountDurationLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/shopDiscountDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView6"
android:layout_alignLeft="#+id/shopDiscount"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/shopDiscount"
android:layout_alignParentRight="true"
android:text="#string/discountRateLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:background="#drawable/roundbutton"
android:text="#string/discountPublishButtonLabel"
android:textColor="#color/white"
android:onClick="SubmitData"
android:width="250dp" />
<EditText
android:id="#+id/shopCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/shopName"
android:ems="10"
android:inputType="text" />
<EditText
android:id="#+id/shopDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/shopLocation"
android:layout_below="#+id/shopLocation"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="number" />
<EditText
android:id="#+id/shopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:ems="10"
android:inputType="text">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/categoriesSpinner"
android:layout_alignRight="#+id/textView2"
android:text="#string/discountCategoryLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<Spinner
android:id="#+id/categoriesSpinner"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_above="#+id/shopName"
android:layout_alignLeft="#+id/button1"
android:layout_marginBottom="16dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView2"
android:layout_marginTop="206dp"
android:text="#string/discountCityLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/shopCity"
android:layout_alignLeft="#+id/textView5"
android:layout_marginBottom="18dp"
android:text="#string/discountShopLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView1"
android:layout_marginTop="14dp"
android:gravity="right"
android:text="#string/addDiscountMsg"
android:textAlignment="viewEnd"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textDirection="anyRtl" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Do it like this , it will work :
<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"
android:background="#color/background"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textDirection="anyRtl"
tools:context=".AddDiscountActivity" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="19dp"
android:text="#string/discountLocationLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/shopLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignRight="#+id/shopCity"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView5"
android:layout_below="#+id/shopDiscount"
android:layout_marginTop="21dp"
android:text="#string/discountDurationLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<EditText
android:id="#+id/shopDiscountDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView6"
android:layout_alignLeft="#+id/shopDiscount"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/shopDiscount"
android:layout_alignParentRight="true"
android:text="#string/discountRateLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView6"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:background="#drawable/roundbutton"
android:text="#string/discountPublishButtonLabel"
android:textColor="#color/white"
android:onClick="SubmitData"
android:width="250dp" />
<EditText
android:id="#+id/shopCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/shopName"
android:ems="10"
android:inputType="text" >
</EditText>
<EditText
android:id="#+id/shopDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/shopLocation"
android:layout_below="#+id/shopLocation"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="number" />
<EditText
android:id="#+id/shopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:ems="10"
android:inputType="text">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/categoriesSpinner"
android:layout_alignRight="#+id/textView2"
android:text="#string/discountCategoryLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<Spinner
android:id="#+id/categoriesSpinner"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_above="#+id/shopName"
android:layout_alignLeft="#+id/button1"
android:layout_marginBottom="16dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView2"
android:layout_marginTop="206dp"
android:text="#string/discountCityLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/shopCity"
android:layout_alignLeft="#+id/textView5"
android:layout_marginBottom="18dp"
android:text="#string/discountShopLabel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView1"
android:layout_marginTop="14dp"
android:gravity="right"
android:text="#string/addDiscountMsg"
android:textAlignment="viewEnd"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textDirection="anyRtl" />
</RelativeLayout>
</ScrollView>
Hope help you
I think you must enclose your relative layout in your scrollview ( before defining and after closing ) .
EDIT : You must also enclose your relative layout in Liner Layout
ex :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textDirection="anyRtl"
tools:context=".AddDiscountActivity" >
</RelativeLayout>
</LinearLayout>
</SrcollView>

How to do Android layout wrap with contents?

The contents of my android app are increasing from the layout portion, but I want to wrap the layout as contents are increasing. Can I adjust my all contents on a single relative layout or is this possible on any other layout?
Layout Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/ttl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ep"
android:textColor="#00ccff"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginLeft="70dp"
android:layout_marginTop="15dp"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/eprice"
android:layout_marginTop="64dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/ep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:text="#string/epval"
android:inputType="text"
android:layout_marginLeft="245dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/molcal"
android:layout_marginTop="100dp"
android:textColor="#00cc00"
android:textSize="18sp"
android:textStyle="bold"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/molfac"
android:layout_marginTop="135dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/molex"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="122dp"
android:text="#string/molex"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/frght"
android:layout_marginTop="180dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/frght"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="167dp"
android:text="#string/frghtport"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/whlfrg"
android:layout_marginTop="225dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/whar"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="212dp"
android:text="#string/whlfrgval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/storage"
android:layout_marginTop="270dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/storage"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="257dp"
android:text="#string/storageval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/expdev"
android:layout_marginTop="305dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/expdev"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="302dp"
android:text="#string/expdeval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clear"
android:layout_marginTop="350dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/clear"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="347dp"
android:text="#string/clearval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/survey"
android:layout_marginTop="395dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/survey"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="392dp"
android:text="#string/surveyval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/transit"
android:layout_marginTop="440dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/transit"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="438dp"
android:text="#string/transitval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/total"
android:layout_marginTop="485dp"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/total"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginTop="483dp"
android:text="#string/totval"
android:inputType="text"
android:layout_marginLeft="230dp"
/>
</RelativeLayout>
Please Use below XML code instead of your code, it will solve your problem.
<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="wrap_content" >
<TextView
android:id="#+id/ttl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="ep"
android:textColor="#00ccff"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="eprice"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/ep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="245dp"
android:layout_marginTop="60dp"
android:inputType="text"
android:text="epval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="molcal"
android:textColor="#00cc00"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="135dp"
android:text="molfac"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/molex"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="122dp"
android:inputType="text"
android:text="molex" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:text="frght"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/frght"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="167dp"
android:inputType="text"
android:text="frghtport" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="whlfrg"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/whar"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="212dp"
android:inputType="text"
android:text="whlfrgval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="270dp"
android:text="storage"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/storage"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="257dp"
android:inputType="text"
android:text="storageval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="305dp"
android:text="expdev"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/expdev"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="302dp"
android:inputType="text"
android:text="expdeval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="350dp"
android:text="clear"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/clear"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="347dp"
android:inputType="text"
android:text="clearval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="395dp"
android:text="survey"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/survey"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="392dp"
android:inputType="text"
android:text="surveyval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="440dp"
android:text="transit"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/transit"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="438dp"
android:inputType="text"
android:text="transitval" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="485dp"
android:text="total"
android:textColor="#BBB000"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/total"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="230dp"
android:layout_marginTop="483dp"
android:inputType="text"
android:text="totval" />
</RelativeLayout>
</ScrollView>
Ok it is a good question. You can set the layout height and width to wrap content and if you need to add other things you can use the following tags:
android:layout_below="#+id/textView1"
android:layout_above="#+id/textView1"
android:layout_toRightOf="#+id/textView1"
android:layout_toLeftOf="#+id/textView1"
According to me, Relative Layout is the best to use over others.

Categories

Resources