Please help my ListView stop vertical scrolling - android

I've created a ListView in a nested LinearLayouts with Horizontal scrolling in an attempt to display long records with the capability for Horizontal scrolling, but now I'm unable to scroll the ListView vertically.
Here is my XML setup. Can you help me figure out why the ListView stop scrolling. I've found several article tried difference Width, Height and Weight layout, but nothing seems to work.
Thank you in advance for your help.
<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"
tools:context=".ProductReview" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="40sp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/lyellow_strip"
android:scaleType="centerCrop"
android:src="#drawable/shell_strip" />
<ImageView
android:id="#+id/imgVCancel"
android:layout_width="27sp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView2"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="224dp"
android:clickable="true"
android:contentDescription="#string/btnCancel"
android:onClick="Cancel"
android:src="#drawable/cancel32" />
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageView2" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="527dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginLeft="40dp"
android:orientation = "horizontal">
<TextView
android:id="#+id/code"
android:layout_width="110sp"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="Type"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/manufacturer"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/code"
android:maxLines="1"
android:text="Manu"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/name"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/manufacturer"
android:maxLines="1"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/visc40"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/name"
android:maxLines="1"
android:text="Visc 40"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/visc100"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/visc40"
android:maxLines="1"
android:text="Visc 100"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/viscindex"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/visc100"
android:maxLines="1"
android:text="Visc Index"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/den15c"
android:layout_width="80sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/viscindex"
android:maxLines="1"
android:text="Den#15c"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/name1"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/den15c"
android:maxLines="1"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/visctext"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/name1"
android:maxLines="1"
android:text="Visc Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/baseoiltype"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/visctext"
android:maxLines="1"
android:text="Base Oil Type"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/name2"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/baseoiltype"
android:maxLines="1"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/baseoil"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/name2"
android:maxLines="1"
android:text="Base Oil"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/additives"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/baseoil"
android:maxLines="1"
android:text="Additives"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/name3"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/additives"
android:maxLines="1"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/otheradditives"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/name3"
android:maxLines="1"
android:text="Other Properties"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/thickener"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/otheradditives"
android:maxLines="1"
android:text="Thickener"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/nlgi"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/thickener"
android:maxLines="1"
android:text="NLGI"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/name4"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/nlgi"
android:maxLines="1"
android:text="Product Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/comments"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/name4"
android:maxLines="1"
android:text="Comments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/packages"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/comments"
android:maxLines="1"
android:text="Packages"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/area"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/packages"
android:maxLines="1"
android:text="Areas"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/usage"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_toRightOf="#+id/area"
android:maxLines="1"
android:text="Usage"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginLeft="-4060dp"
android:layout_marginTop="30dp"
android:orientation = "horizontal">
<ListView
android:id="#+id/listView1"
android:layout_width="0dip"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:fastScrollEnabled="true"
android:headerDividersEnabled="true"
android:smoothScrollbar="true" >
</ListView>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>

I've figured out what to do. This is probably not the best way, but it work for us. I put the column headers one linear layout and the ListView in another. Thanks.

Related

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 RelativeLayout, hiding views and pushing the views beneath up

I have a RelativeLayout which includes a Spinner and some RadioButtons, based on the selection of these I have to hide some views and make others visible. The problem is if I make the views GONE by view.setVisibility(View.GONE) the layout gets messed up, the views overlap, if I use view.Visibility(View.INVISIBLE) everything is fine but the missing views create a void on the page. I want to push the views beneath up to properly augment the page. Below is a better explanation:
So far the code I have is:
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_app" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="60dp"
android:background="#drawable/drop_down" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/textView5"
android:layout_marginTop="30dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<Button
android:id="#+id/button2"
android:layout_width="170dp"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignRight="#+id/spinner1"
android:background="#drawable/btn_calendar"
android:textColor="#FFBF00" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:scaleType="centerCrop" />
<AutoCompleteTextView
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/spinner1"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imageView1"
android:ems="6"
android:hint="xx xx"
android:inputType="textPersonName"
android:maxLength="25"
android:textColor="#002f44" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:padding="03dp"
android:textColor="#610B0B" />
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/spinner1"
android:layout_marginTop="20dp"
android:text="xxx "
android:textColor="#002f44"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/spinner1"
android:layout_alignTop="#+id/textView4"
android:layout_marginTop="-5dp"
android:background="#drawable/widget_style"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="xxx"
android:textColor="#002f44" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="xxx"
android:textColor="#002f44" />
</RadioGroup>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/radioGroup1"
android:layout_marginTop="25dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<AutoCompleteTextView
android:id="#+id/autoname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignRight="#+id/spinner1"
android:ellipsize="end"
android:ems="8"
android:hint="xx xx"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#002f44" >
</AutoCompleteTextView>
<Button
android:id="#+id/button4"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/button1"
android:layout_marginLeft="05dp"
android:layout_marginTop="66dp"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button01"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button02"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_alignRight="#+id/editText1"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You should use alignWithParentIfMissing attribute.
I've reworked your layout, try it
<?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:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="60dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="30dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<Button
android:id="#+id/button2"
android:layout_width="170dp"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignParentRight="true"
android:textColor="#FFBF00" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:scaleType="centerCrop" />
<AutoCompleteTextView
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imageView1"
android:ems="6"
android:hint="xx xx"
android:inputType="textPersonName"
android:maxLength="25"
android:textColor="#002f44" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:padding="03dp"
android:textColor="#610B0B" />
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="xxx "
android:textColor="#002f44"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginTop="-5dp"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="xxx"
android:textColor="#002f44" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="xxx"
android:textColor="#002f44" />
</RadioGroup>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/radioGroup1"
android:layout_marginTop="25dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<AutoCompleteTextView
android:id="#+id/autoname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignParentRight="true"
android:ellipsize="end"
android:ems="8"
android:hint="xx xx"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#002f44" >
</AutoCompleteTextView>
<Button
android:id="#+id/button4"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/button1"
android:layout_marginLeft="05dp"
android:layout_marginTop="66dp"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button01"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button02"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_alignRight="#+id/editText1"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Use LinearLayout(vertical) inside ScrollView and create RelativeLayouts as child of this LinearLayout. Set height of these RelativeLayout as wrap content, so that as you set visibility of items as GONE its height will shrink.
Now as per image that you have given here, you can have spinner first then below that a relative layout which will contain two (horizontal) items that you wanna hide. then next two (horizontal) items in another layout and then your image, editText and Button in third layout.
So you hide any relative layout others will arrange properly.
I would recommend to create a view of height 1dp with transparent background below texView4 and then set android:layout_below="#id/view" attribute for textView5. Here is how the changes to the layout would look like:
</RadioGroup> <!-- RadioGroup ends -->
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/textView4"
android:background="#color/transparent"/>
<!-- Changed layout_below attribute value -->
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#id/view"
android:layout_marginTop="25dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
And here is how the layout looks like with textView4 and RadioGroup gone:

Android background leaves some white space at bottom

i have a layout in my android project it takes input from edittext and sends the mail from this information but in layout the background does not show up on whole screen it leaves some space at the bottom so it do not look good
this is my layout:
<?xml version="1.0" encoding="utf-8"?>
<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:scrollbarStyle="insideOverlay"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="530dp"
android:background="#drawable/f4kf6msk"
android:fillViewport="true"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/to"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#6495ed" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/to"
android:text="#string/app"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#6495ed" />
<EditText
android:id="#+id/from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:textColor="#6495ed"
android:textStyle="bold"
android:layout_below="#+id/textView2"
android:ems="10"
android:hint="#string/from"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:ems="10"
android:textColor="#6495ed"
android:textStyle="bold"
android:hint="#string/too"
android:inputType="textEmailAddress"
/>
<Button
android:id="#+id/button1d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/message"
android:background="#android:color/transparent"
android:gravity="center"
android:text="#string/send"
android:textColor="#6495ed" />
<View
android:id="#+id/View0dfd1"
android:layout_width="fill_parent"
android:layout_height="3dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#808080"
android:paddingBottom="3dp" />
<EditText
android:id="#+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="23dp"
android:textColor="#6495ed"
android:hint="#string/sub1"
android:textStyle="bold"
android:ems="10" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/from"
android:text="#string/sub"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#6495ed"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="#string/Message"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#6495ed"
android:textStyle="bold" />
<EditText
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/subject"
android:ems="10"
android:gravity="top"
android:hint="#string/mess"
android:inputType="textMultiLine"
android:lines="11"
android:textColor="#6495ed"
android:textStyle="bold" />
<View
android:id="#+id/View0sd1"
android:layout_width="fill_parent"
android:layout_height="3dip"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/button1d"
android:layout_marginTop="14dp"
android:background="#808080"
android:paddingBottom="3dp" />
</RelativeLayout>
</ScrollView>
try to put backround in scroll view property instead in relative layout

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>

Categories

Resources