Managing width in xml - android

I'm working on my xml file in android studio.
I want to have "surnameEditText" and "nameEditText", Picture, which have arrows next to them, to have the same width as the input forms that are located below them.
How to do that? This is my code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pozadina"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.xyz.ui.RegisterActivity">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/signUpTextView"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<TextView
android:id="#+id/signUpTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="Sign up"
android:textAlignment="center"
android:textColor="#ffffffff"
android:textSize="30sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="#ffffffff"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:textColorHint="#95ffffff" />
<EditText
android:id="#+id/surnameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:backgroundTint="#ffffffff"
android:ems="10"
android:hint="Surname"
android:inputType="textPersonName"
android:textColorHint="#95ffffff" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Top views only have margin 10dp and rest of the views have marginLeft 16dp. Change top view's margin to 16dp as well.

Related

Android - How to structure a simple Layout

I still dont understand how to use layouts when I'm trying to program for multiple screen sizes. I need to insert an image saying "Facebook" with a distance to the top and the textboxes a bit down.
But if I use margins it will mess up my layout on bigger screen sizes.
Can someone explain to me the layout of this picture:
You can solve this by creating layouts for different screen sizes.for that create separate layout folders for different screens and put corresponding layout there.For example
layout-sw720dp for 720dp devices /
layout-sw600dp for 600dp devices
change the dp value according to your need.
you can also make images for different sizes
OR
you can try this layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/amna2"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.codeslayers.amnalocations.LoginActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/amna" />
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp">
<EditText
android:id="#+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Van Name"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:textColor="#color/amna3"
android:textColorHint="#color/amna3"
android:textColorLink="#color/amna3" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:maxLines="1"
android:singleLine="true"
android:textColor="#color/amna3"
android:textColorHint="#color/amna3"
android:textColorLink="#color/amna3" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/district"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Destination"
android:maxLines="1"
android:singleLine="true"
android:textColor="#color/amna3"
android:textColorHint="#color/amna3"
android:textColorLink="#color/amna3" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/dbname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Database Name"
android:maxLines="1"
android:singleLine="true"
android:textColor="#color/amna3"
android:textColorHint="#color/amna3"
android:textColorLink="#color/amna3" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/action_sign_in"
android:textColor="#color/amna4" />/
android:textStyle="bold" />
</LinearLayout>
You can also do some thing like this with different dimen.xml (values-sw600dp,values-sw720dp) . So you dont have to duplicate the layout files.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textSize="32dp"
android:layout_above="#+id/inputFields"
android:id="#+id/facebook_logo"
android:gravity="center"
android:text="Facebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_marginTop="45dp"
android:layout_centerInParent="true"
android:id="#+id/inputFields"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:gravity="center"
android:text="Forgot password ?"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:id="#+id/signupTxt"
android:layout_marginBottom="10dp"
android:layout_alignParentBottom="true"
android:text="Signup for Facebook"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_alignParentRight="true"
android:src="#drawable/rotate_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

No shadow/elevation underneath second card if there are two card in the layout. Why?

I have 2 cards in a single RelativeLayout.
The problem is that there is no elevation or shadow underneath the second card.
See the screenshot here: screenshot
Here's what I have done in the xml file:
<?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"
android:background="#color/colorPrimary"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.abc.xyz.abcActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/cba_screen_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/cba_screen_text"
android:textColor="#android:color/white"
android:textSize="#dimen/cba_screen_text"
android:gravity="center_horizontal|center_vertical"
android:layout_gravity="center_horizontal|center_vertical"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/signup_screen_first_cardview_top_margin"
app:contentPadding="10dp"
app:cardBackgroundColor="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<!-- N Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/abc_screen_name_label_topmargin">
<EditText android:id="#+id/input_n"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textColor="#color/colorPrimary"
android:hint="N" />
</android.support.design.widget.TextInputLayout>
<!-- E Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/abc_screen_name_label_topmargin"
android:layout_marginBottom="#dimen/abc_screen_name_label_topmargin">
<EditText android:id="#+id/input_e"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textColor="#color/colorPrimary"
android:hint="E" />
</android.support.design.widget.TextInputLayout>
<!-- P Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/abc_screen_name_label_topmargin"
android:layout_marginBottom="#dimen/abc_screen_name_label_topmargin">
<EditText android:id="#+id/input_p"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textColor="#color/colorPrimary"
android:hint="P"/>
</android.support.design.widget.TextInputLayout>
<!-- S Button -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_s"
android:layout_width="#dimen/s_btn_width"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/c_btn_topmargin"
android:layout_gravity="center_horizontal"
android:padding="12dp"
android:text="C"
android:textSize="#dimen/s_btn_text_size"/>
<TextView android:id="#+id/l"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/a_topmargin"
android:text="A"
android:gravity="center"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_gravity="center_horizontal|center_vertical"
android:text="OR"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#android:color/white"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentPadding="10dp"
app:cardElevation="2dp"
app:cardBackgroundColor="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.gms.common.SignInButton
android:id="#+id/google_login_button"
android:layout_width="#dimen/sign_in_btn_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<com.facebook.login.widget.LoginButton
android:id="#+id/facebook_login_button"
android:layout_width="#dimen/sign_in_btn_width"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</RelativeLayout>
Please let me know why is this happening and how can I have the shadow/elevation underneath the second card too?
Your LinearLayout is wrapping its height, cutting off the shadow of the card at the bottom.
Either put some padding on the bottom of the LinearLayout or set it to match_parent on its height.
PS that outer RelativeLayout is useless -- get rid of it and put all the padding and background on the inner LinearLayout

How do I ensure the buttons align horizontally in this Android login dialog?

I'm creating a login dialog on Android where I want two buttons to align horizontally both on the top and bottom edge, irregardless of the screen size. Sometimes "Forgot password" will break over two lines, sometimes not. I do not want to impose a minHeight on the buttons, and would prefer a solution based on XML design only (not code).
Landscape is fine:
Portrait, default implementation leaves the login button shorter than "forgot password"
One solution I tried was setting match_parent for the layout_height param of the first button. Didn't quite work:
XML:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/terms_layout"
android:layout_marginTop="10dp"
>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/login"
android:textSize="18sp"
android:id="#+id/dialog_login_button_login"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/forgotPassword"
android:textSize="18sp"
android:id="#+id/dialog_login_button_forgot_password"
/>
</LinearLayout>
Use RelativeLayout and make "Login" button to align to the top and bottom of "Forgot Password" Button
As #manjusg answered, make the Login button align the bottom and top to the other button.
Here is how I did it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/terms_layout"
android:layout_marginTop="10dp">
<View
android:id="#+id/center_strut"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_centerInParent="true" />
<Button
android:layout_width="0dp"
android:layout_height="0dp"
android:text="Login"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/center_strut"
android:layout_alignBottom="#+id/dialog_login_button_forgot_password"
android:layout_alignTop="#+id/dialog_login_button_forgot_password"
android:id="#+id/dialog_login_button_login" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignLeft="#+id/center_strut"
android:text="Forgot Password"
android:textSize="18sp"
android:id="#+id/dialog_login_button_forgot_password" />
</RelativeLayout>
</LinearLayout>
replace your xml with this xml
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/terms_layout"
android:layout_marginTop="10dp"
android:weightSum="2"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/login"
android:textSize="18sp"
android:id="#+id/dialog_login_button_login"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/forgotPassword"
android:textSize="18sp"
android:id="#+id/dialog_login_button_forgot_password"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</LinearLayout>
check this
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Login"
android:id="#+id/button"/>
<Button
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="FORGOT PASSWORD"
android:id="#+id/button2"/>
</LinearLayout>
<LinearLayout
android:layout_alignBottom="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:layout_height="wrap_content">
<View
android:layout_width="0.5dp"
android:layout_height="wrap_content"
android:background="#000000"/>
</LinearLayout>
</RelativeLayout>

Adding a Line Separator between two TextViews in Android XML

Recently I started practicing Android Development and I am stuck at a very basic problem. Since I am a beginner in this field, I am asking for your help.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:text="Name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="18sp"
/>
<EditText
android:id="#+id/player_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"
/>
<TextView
android:text="Name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="18sp"
/>
<EditText
android:id="#+id/player_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"
/>
</LinearLayout>
In this XML scheme, I am trying to put a text followed by text-space and repeating it again.
e.g. Name1 ___________________ //Next Line//
Name2 ___________________
But the problem is that Name2 is not going into the next line and staying in the same line .
Please tell me how to fix it.
Thanks in advance
In these type of scenarios I create a layout within a layout.
So each line of yours will be a layout and hence. You can only those elements in that line.
<?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:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/lblName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Name"
android:textSize="20dp" />
<EditText
android:id="#+id/txtName"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ems="10"
android:gravity="left" >
<requestFocus />
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/lblName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Name"
android:textSize="20dp" />
<EditText
android:id="#+id/txtName1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ems="10"
android:gravity="left" >
</EditText>
</RelativeLayout>
You need to add orientation = vertical and I've changed your widths to match parent.
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Name1" android:textColor="#000000" android:textSize="18sp"/>
<EditText
android:id="#+id/player_name1" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Name2" android:textColor="#000000" android:textSize="18sp"/>
<EditText
android:id="#+id/player_name2" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="#integer/abc_max_action_buttons"/>
</LinearLayout>
Not sure exactly what height space you want, but have used your dimensions.

Android Footer Fixed On Bottom And Will Sit On Top Of Other Views

I want to have two buttons that is fixed on the bottom screen like a footer and other views won't make pass on it or overlap on the two buttons. It will just stay still on the bottom always. Sorry for my English. Please help me. Btw I cannot post images so it requires 10 reputation that's why I used online image viewing. Sorry for that.
Here is the screenshot of my work which is wrong
http://postimg.org/image/pzry53ey9/
As you can see the multiline edit text overlaps on the two buttons as well as the scrollview. How to fix that?
Here is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
your layout is quite complex for a simple view but i have modified it to achieve what you want
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/relativeLayout1"
android:layout_marginBottom="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
You don't need the RelativeLayout containing the LinearLayout that holds your buttons...get rid of the RelativeLayout and specify the LinearLayout like so:
<LinearLayout
android:id="#+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
Next, since your parent Layout is RelativeLayout, you'll need to specify the positioning of your ScrollView containing the EditText:
<ScrollView
android:layout_above="#+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
Also, if you want the buttons to stay at the very bottom of your view then remove this line from the parent Layout:
android:paddingBottom="#dimen/activity_vertical_margin"
Hope this helps!
Your root layout file is relative layout. It allows overlapping of UI elements(z-index placement). So you need to provide the boundary for a view to extend. Assign a android:id= "#+id\relativeLayout" to your relative layout(bottom not root). Then in your scrollview put
android:layout_above="#+id\relativeLayout". Follow similar approach for other views.

Categories

Resources