I am creating a registration screen strangely I am facing an issue with padding a layout which has sign up text.
I would like to align it according to text box shown in the screen shot below. I am not sure why this giving me this strange issue?
Below is the code I have tried:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundcolor"
android:orientation="vertical" >
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="#string/signUp"
android:textColor="#000000"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/linearlayout1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/header"
android:padding="10dp" >
<EditText
android:id="#+id/namefEDIT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/textbox"
android:hint="#string/fname"
android:padding="5dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/fnamelinearlayout"
android:padding="10dp" >
<EditText
android:id="#+id/namelEDIT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/textbox"
android:hint="#string/lname"
android:padding="5dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout3"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/lnamelinearlayout"
android:padding="10dp" >
<EditText
android:id="#+id/numberEDIT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/textbox"
android:hint="#string/mobilenumber"
android:inputType="numberSigned"
android:padding="5dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout4"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/mobilelinearlayout"
android:padding="10dp" >
<EditText
android:id="#+id/pEDIT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/textbox"
android:hint="#string/password"
android:inputType="textPassword"
android:padding="5dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout5"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/passwordlinearlayout"
android:layout_marginTop="15dp"
android:background="#drawable/button_selector"
android:orientation="vertical" >
<TextView
android:id="#+id/textEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:padding="10dp"
android:textSize="20sp"
android:text="#string/signText"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
Below is the screen shot:
This layout should do the same:
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="#string/signUp"
android:textColor="#000000"
android:textSize="20sp" />
<EditText
android:id="#+id/namefEDIT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/textbox"
android:hint="#string/fname"
android:padding="5dp"
android:layout_margin="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
<EditText
android:id="#+id/namelEDIT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/textbox"
android:hint="#string/lname"
android:padding="5dp"
android:layout_margin="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
<EditText
android:id="#+id/numberEDIT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/textbox"
android:hint="#string/mobilenumber"
android:inputType="numberSigned"
android:padding="5dp"
android:layout_margin="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
<EditText
android:id="#+id/pEDIT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/textbox"
android:hint="#string/password"
android:inputType="textPassword"
android:padding="5dp"
android:layout_margin="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="20sp" />
<TextView
android:id="#+id/textEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_vertical"
android:padding="10dp"
android:layout_margin="10dp"
android:textSize="20sp"
android:text="#string/signText"
android:textColor="#000000" />
</LinearLayout>
Related
I have a bunch of EditText, TextViews, Spinners and Other components in my ScrollView, Now what happens is, when i selected an item from any Spinner, the Scrollview scrolls up automatically and the first EditText gets the focus.
How to prevent these otherviews getting focus and ScrollView scrolling up?
I have already tried android:descendantFocusability="beforeDescendants" but it did not work "adjustPan" also not working
Please help
here is my xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/screen_background"
android:orientation="vertical">
<include
layout="#layout/appbar_registration"
android:layout_width="match_parent"
android:layout_height="wrap_content"></include>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SIGN UP"
android:textColor="#color/background_color"
android:textSize="30sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Create an account"
android:textColor="#color/registration_text_gray" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonlinear"
android:layout_below="#+id/linear"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Name"
android:inputType="textCapWords"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_father_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Father's Name"
android:inputType="textCapWords"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:orientation="horizontal"
android:weightSum="10">
<Spinner
android:id="#+id/registration_spnr_country"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9.5"
android:background="#android:color/transparent" />
<ImageView
android:id="#+id/registration_img_country"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:src="#drawable/ic_spinner_arrow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:orientation="horizontal"
android:weightSum="10">
<Spinner
android:id="#+id/registration_spnr_state"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9.5"
android:background="#android:color/transparent"
android:clickable="false" />
<ImageView
android:id="#+id/registration_img_state"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:clickable="false"
android:src="#drawable/ic_spinner_arrow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_district"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="District"
android:inputType="textCapWords"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_city_village"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="City / Village"
android:inputType="textCapWords"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Mobile"
android:inputType="phone"
android:lines="1"
android:maxLength="10"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<AutoCompleteTextView
android:id="#+id/registration_edt_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:orientation="horizontal"
android:weightSum="10">
<Spinner
android:id="#+id/registration_spnr_last_exam_passed"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9.5"
android:background="#android:color/transparent"
android:entries="#array/last_exam_passed" />
<ImageView
android:id="#+id/registration_img_last_exam_passed"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:src="#drawable/ic_spinner_arrow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:padding="5dp">
<TextView
android:id="#+id/registration_txt_date_of_birth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:lines="1"
android:padding="5dp"
android:text="Date of Birth"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:padding="5dp">
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:weightSum="1">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:buttonTint="#color/colorPrimary"
android:checked="false"
android:text="Male"
android:textColor="#color/registration_hint_color" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:buttonTint="#color/colorPrimary"
android:checked="false"
android:text="Female"
android:textColor="#color/registration_hint_color" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:orientation="horizontal"
android:weightSum="10">
<Spinner
android:id="#+id/registration_spnr_cast"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9.5"
android:background="#android:color/transparent"
android:entries="#array/cast" />
<ImageView
android:id="#+id/registration_img_cast"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:src="#drawable/ic_spinner_arrow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:orientation="horizontal"
android:weightSum="10">
<Spinner
android:id="#+id/registration_spnr_religion"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9.5"
android:background="#android:color/transparent"
android:entries="#array/religion" />
<ImageView
android:id="#+id/registration_img_religion"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:src="#drawable/ic_spinner_arrow" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:fontFamily="sans-serif"
android:hint="Password"
android:inputType="textPassword"
android:lines="1"
android:maxLength="18"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_confirm_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:fontFamily="sans-serif"
android:hint="Confirm Password"
android:inputType="textPassword"
android:lines="1"
android:maxLength="18"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background">
<EditText
android:id="#+id/registration_edt_parent_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="Parent Code (Optional)"
android:inputType="textCapWords"
android:lines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="#color/registration_hint_color"
android:textColorHint="#color/registration_hint_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corder_background"
android:padding="5dp">
<CheckBox
android:id="#+id/registration_chk_agreement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:buttonTint="#color/colorPrimary"
android:lines="1"
android:padding="10dp"
android:text="I Agree to the Terms And Conditions"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/registration_hint_color" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/buttonlinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="vertical">
<Button
android:id="#+id/registration_btn_sign_up"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="#color/colorPrimary"
android:lines="1"
android:singleLine="true"
android:text="Submit"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Add
android:focusable="true"
android:descendantFocusability="beforeDescendants"
on scrollview
HI,
In my android app,the emulator screen is rotating in landscape i didn't get the full view of a registration form. But in portrait mode it works perfectly. Please Look through it.Thanks in Advance.
activity_main
<LinearLayout 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:orientation="vertical"
android:padding="10dp"
android:weightSum="1">
<TextView
android:text="Soil Test Based Nutrient Recommendations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAlignment="center"
android:id="#+id/title"
android:layout_weight="0.03" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:text="Crop"/>
<Spinner android:id="#+id/spinFood"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="State"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="#+id/textView" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner" />
<TextView
android:text="Category"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner2" />
<TextView
android:text="Soil_Texture"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner3" />
<TextView
android:text="pH"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView4" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/editText" />
<TextView
android:text="Available Phosphorus"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView5" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/editText2" />
<TextView
android:text="Available Pottassium"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView6" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/editText3" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button" />
</LinearLayout>
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="1">
<TextView
android:text="Soil Test Based Nutrient Recommendations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textAlignment="center"
android:id="#+id/title"
android:layout_weight="0.03" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:text="Crop"/>
<Spinner android:id="#+id/spinFood"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="State"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:id="#+id/textView" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner" />
<TextView
android:text="Category"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView2" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner2" />
<TextView
android:text="Soil_Texture"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner3" />
<TextView
android:text="pH"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView4" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/editText" />
<TextView
android:text="Available Phosphorus"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView5" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/editText2" />
<TextView
android:text="Available Pottassium"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView6" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/editText3" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button" />
</LinearLayout>
</ScrollView>
Just wrap into ScrollView to Main LinearLayout
Add android:screenOrientation="portrait" to the activity you want to disable landscape mode.
The layout look nice in Android Studio but the design slightly run when running in real device.
Android Studio
Real device
Can someone tell me what's wrong here ? Any help would be greatly appreciated. Below is my xml layout code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/bg_login"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<EditText
android:id="#+id/name"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:hint="#string/hint_name"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_login"
android:textColorHint="#color/input_login_hint" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:hint="#string/hint_password"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_login"
android:textColorHint="#color/input_login_hint" />
<!-- Login Button -->
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="#color/btn_login_bg"
android:text="#string/btn_login"
android:textColor="#color/btn_login" />
<Button
android:layout_width="327dp"
android:layout_height="33dp"
android:id="#+id/forget"
android:background="#null"
android:textColor="#color/white"
android:text="Forget Password ?"
android:textSize="12dp"
android:paddingLeft="150dp"
android:textAllCaps="false"
/>
<Button
android:id="#+id/btnLinkToRegisterScreen"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#null"
android:text="Create account"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
You need to put name edit text out of the inner linear layout, just update your xml as follows:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/bg_login"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<EditText
android:id="#+id/name"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:hint="#string/hint_name"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_login"
android:textColorHint="#color/input_login_hint" />
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:hint="#string/hint_password"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/input_login"
android:textColorHint="#color/input_login_hint" />
<!-- Login Button -->
<Button
android:id="#+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:background="#color/btn_login_bg"
android:text="#string/btn_login"
android:textColor="#color/btn_login" />
<Button
android:layout_width="327dp"
android:layout_height="33dp"
android:id="#+id/forget"
android:background="#null"
android:textColor="#color/white"
android:text="Forget Password ?"
android:textSize="12dp"
android:paddingLeft="150dp"
android:textAllCaps="false"
/>
<Button
android:id="#+id/btnLinkToRegisterScreen"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#null"
android:text="Create account"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="15dp" />
</LinearLayout></LinearLayout>
problem is that there is un even padding given to the editText for the password and email,
try this out
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_dark"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:background="#android:color/holo_purple"
android:ems="10"
android:hint="username"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:background="#android:color/holo_purple"
android:ems="10"
android:hint="password"
android:inputType="textPassword" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:background="#android:color/darker_gray"
android:text="Login"
android:textAllCaps="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#android:color/transparent"
android:text="Forgot password"
android:textAllCaps="false" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:background="#android:color/transparent"
android:text="Create Account"
android:textAllCaps="false" />
</LinearLayout>
output
this will remain same for all the screens
I have the following xml layout:
<?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="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:textStyle="bold"
android:text="#string/form_header"
android:textSize="10pt" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_below="#+id/textHeader">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textComp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:textColor="#color/red"
android:text="#string/form_comp"
android:textSize="7pt" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textComp" >
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_title"
android:textSize="7pt" />
<Spinner
android:id="#+id/title_spinner"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textTitle"
android:focusable="true"
android:padding="10dip" />
<TextView
android:id="#+id/textFname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textTitle"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_fname"
android:textSize="7pt" />
<EditText
android:id="#+id/editFname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_below="#+id/textTitle"
android:layout_toRightOf="#id/textFname"
android:ems="10"
android:maxLength="15" />
<TextView
android:id="#+id/textLname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textFname"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_lname"
android:textSize="7pt" />
<EditText
android:id="#+id/editLname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_below="#+id/textFname"
android:layout_toRightOf="#id/textLname"
android:ems="10"
android:maxLength="15" />
<TextView
android:id="#+id/textTel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textLname"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_tel"
android:textSize="7pt" />
<EditText
android:id="#+id/editTel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:layout_below="#+id/textLname"
android:layout_toRightOf="#id/textTel"
android:ems="10"
android:maxLength="15" />
<TextView
android:id="#+id/textEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textTel"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_email"
android:textSize="7pt" />
<EditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:layout_below="#+id/textTel"
android:layout_toRightOf="#id/textEmail"
android:ems="10"
android:maxLength="25" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout1" >
<TextView
android:id="#+id/textDep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_dep"
android:textSize="7pt" />
<EditText
android:id="#+id/editDep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_toRightOf="#id/textDep"
android:ems="10"
android:maxLength="25" />
<TextView
android:id="#+id/textDest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_dest"
android:layout_below="#+id/textDep"
android:textSize="7pt" />
<EditText
android:id="#+id/editDest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_toRightOf="#id/textDest"
android:layout_below="#+id/textDep"
android:ems="10"
android:maxLength="25" />
<TextView
android:id="#+id/textNpersons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_npersons"
android:layout_below="#+id/editDest"
android:textSize="7pt" />
<EditText
android:id="#+id/editNpersons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:layout_toRightOf="#id/textNpersons"
android:layout_below="#+id/editDest"
android:ems="10"
android:maxLength="3" />
<TextView
android:id="#+id/textDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_date"
android:layout_below="#+id/textNpersons"
android:textSize="7pt" />
<Spinner
android:id="#+id/spYear"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textNpersons"
android:layout_toRightOf="#id/textDate"/>
<Spinner
android:id="#+id/spMonth"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textNpersons"
android:layout_toRightOf="#id/spYear"/>
<Spinner
android:id="#+id/spDay"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textNpersons"
android:layout_toRightOf="#id/spMonth"/>
<TextView
android:id="#+id/textTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_time"
android:layout_below="#+id/spDay"
android:textSize="7pt" />
<Spinner
android:id="#+id/spTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_toRightOf="#id/textTime"
android:layout_below="#+id/spDay"/>
<TextView
android:id="#+id/textComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dip"
android:text="#string/form_comments"
android:layout_below="#+id/spTime"
android:textSize="7pt" />
<EditText
android:id="#+id/editComms"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="textMultiLine"
android:lines="2"
android:minLines="2"
android:gravity="top|left"
android:maxLines="5"
android:layout_below="#+id/spTime"
android:layout_toRightOf="#id/textComms"
android:scrollbars="vertical"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editComms"
android:layout_centerHorizontal="true"
android:text="#string/form_snd_button" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The ScrollView scrolls fine; however, the last button (#+id/button1) is not shown.
I've tried several combinations with match_parent and wrap_content for the contained layouts but with no luck.
Any ideas?
Thanks in advance.
Edit: Actually I'm writing my app so as to work in both tablets and phones. The above layout that belongs to a fragment works fine for phones.
In the case of tablets, the specific button is not shown. The above layout is attached to the Framelayout:aboutusdet shown in the code below:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/UnitId"/>
<FrameLayout
android:id="#+id/mainfrg"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_alignParentLeft="true"
/>
<FrameLayout
android:id="#+id/aboutusdet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/mainfrg"
android:layout_below="#+id/adView"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
/>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/mainfrg" />
<TabWidget android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
Must be very simple to solve but I'm not able to solve this.
I want to align the "top image and log_in_box", so the whole thing appear in exact center (Horizontal+Vertical center) of the screen.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="#drawable/ic_launcher"
android:contentDescription="" />
<LinearLayout android:id="#+id/log_in_box" android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="User ID"
android:inputType="text" />
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"
android:hint="Password" android:inputType="textPassword" />
<CheckBox android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true"
android:text="Remember Me" android:layout_marginTop="10dp" />
<Button android:id="#+id/log_in" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:text="Log In" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Current Look
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true" >
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="#drawable/ic_launcher"
android:contentDescription="" />
<LinearLayout android:id="#+id/log_in_box" android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="User ID"
android:inputType="text" />
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"
android:hint="Password" android:inputType="textPassword" />
<CheckBox android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true"
android:text="Remember Me" android:layout_marginTop="10dp" />
<Button android:id="#+id/log_in" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:text="Log In" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Try this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="#drawable/ic_launcher"
android:contentDescription="" />
<LinearLayout android:id="#+id/log_in_box" android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="User ID"
android:inputType="text" />
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"
android:hint="Password" android:inputType="textPassword" />
<CheckBox android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true"
android:text="Remember Me" android:layout_marginTop="10dp" />
<Button android:id="#+id/log_in" android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:text="Log In" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription=""
android:src="#drawable/ic_launcher" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="User ID"
android:inputType="text" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Password"
android:inputType="textPassword" />
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:checked="true"
android:text="Remember Me" />
<Button
android:id="#+id/log_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Log In" />