Im trying to make a UI with a few fields in the middle of the screen and a button at the bottom. When i am writing a number in the fields, the keyboard hides part of the interface (which i want it to), but i also need the whole interface to be scrollable so that i can adjust the screen and keep filling the fields with the keyboard on. I've put the whole setup in a relative layout and put it under a scroll view. The posts here say it should work that way but it isnt working for me.
The XML code is
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.maaz.rakattracker.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/farzET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="center"
android:hint="0"
android:inputType="number"
android:singleLine="true"
android:textAlignment="center" />
<TextView
android:id="#+id/farzLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:elevation="0dp"
android:ems="5"
android:text="farz"
android:textAlignment="center"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/sunnatET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="0"
android:inputType="number"
android:singleLine="true"
android:textAlignment="center" />
<TextView
android:id="#+id/sunnatLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:text="Sunnat"
android:textAlignment="center"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/naflET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="center"
android:hint="0"
android:inputType="number"
android:singleLine="true"
android:textAlignment="center" />
<TextView
android:id="#+id/naflLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:text="Nafl"
android:textAlignment="center"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/witrET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="0"
android:inputType="number"
android:singleLine="true"
android:textAlignment="center" />
<TextView
android:id="#+id/witrLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5"
android:text="Witr"
android:textAlignment="center"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/startButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
</RelativeLayout>
</ScrollView>
Kindly help me figure out the issue here.
Thanks
Try to add this code in your Activity inside onCreate() method :
getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_PAN);
In your manifest, add android:windowSoftInputMode="adjustResize" to your Activity tag.
On your manifest file add
<activity
android:name=".YOURACTIVITY"
android:windowSoftInputMode="adjustPan" />
<activity
that because scroll view work only with LinearLayout
Related
[This is the image i need to move up only edittext not the logo ][1]edittext appearing on the top of the keyboard after setting windowSoftInputMode but other views also moving up. is their any way to move only edittext .Thanks in advance
[1]: https://i.stack.imgur.com/NEpf3.png`
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:src="#drawable/logo_light"
android:text="LOGO"
android:textColor="#color/black"
android:textSize="100dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/ll_send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
android:orientation="horizontal">
<EditText
android:id="#+id/editMessage"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:background="#color/white"
android:gravity="center"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:hint="EDIT TEXT"
android:minLines="3"
android:textColorHint="#color/black"
android:scrollHorizontally="false"
android:textColor="#color/white" />
<Button
android:id="#+id/buttonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#color/black"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
`
Try to use framlayout and xml like below
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/edit_text_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_vertical"
android:layout_marginLeft="12dp"
android:background="#null"
android:layout_alignParentBottom="true"
android:hint="Enter you something"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="2000"
android:maxLines="8" />
</FrameLayout>
If your using relative layout , in the edit text tag add this.
android:layout_alignParentBottom="true"
In a screen, I have a edit text on top (large contains space for 4-5 line), image view below that and submit button at bottom. on Keyboard up it should not hide my submit button.
when keyboard appears i am able to resize the window using android:windowSoftInputMode="adjustResize" which allow me not to hide the submit button but it resize my image also which i don't want.
Only submit button should move up when keyboard is visible without resizing image.
I tried frame layout also but it didn't may be i tried wrong way. Any help will be appriciated.
Apply this and let me know is it still happening or not .
activity_mian.xml
<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"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#drawable/xxx.jpg"
android:orientation="vertical"
tools:context=".LoginActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_marginTop="20dp"
android:src="#drawable/logo_app" />
<EditText
android:id="#+id/edtEmail"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/login_textbox"
android:ems="10"
android:hint="Email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textColor="#ffffff"
android:textCursorDrawable="#null" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/edtPassword"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/login_textbox"
android:ems="10"
android:hint="Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#ffffff"
android:textCursorDrawable="#null" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/edtPassword"
android:layout_marginTop="2dp" />
</RelativeLayout>
<CheckBox
android:id="#+id/checkBox_remember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:button="#drawable/checkbox_selector"
android:checked="true"
android:focusable="false"
android:focusableInTouchMode="true"
android:text=" Remember Me"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<Button
android:id="#+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="top|center_vertical|center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#drawable/btn_login" />
</LinearLayout>
</LinearLayout>
</ScrollView>
set your Button, EditText etc.. inside one linear layout followed by one parent ScrollView .
one another thing is that set android:windowSoftInputMode="stateAlwaysHidden"
inside your java file where your xml file is bind .
With some changes in #jigs answer i got it working and posting may be it can help others like me
1) Root layout as normal in my case Relative layout. Then scroll view inside scroll view take a Linear layout where specify edit text + image View. Then bottom button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
android:background="#android:color/white"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollViewNotScrollable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/user_name_container">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
>
<EditText
android:id="#+id/input_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#00000000"
android:ellipsize="start"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="start|center_vertical"
android:hint="#string/feed_hint"
android:imeActionLabel="Submit"
android:imeOptions="actionSend"
android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
android:maxLines="5"
android:minLines="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="25dp"
android:textColor="#color/feed_sub_color"
android:textColorHint="#color/light_gray"
android:textCursorDrawable="#null" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<!--<ScrollView
android:id="#+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:padding="4dp"
android:layout_centerHorizontal="true"
>-->
<ImageView
android:id="#+id/imgPreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:background="#android:color/white"
android:elevation="5dp"
android:padding="4dp"
android:visibility="gone" />
<!--</ScrollView>-->
<ImageView
android:id="#+id/close_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imgPreview"
android:layout_marginLeft="-45dp"
android:layout_marginTop="-20dp"
android:layout_toRightOf="#+id/imgPreview"
android:elevation="5dp"
android:paddingBottom="15dp"
android:src="#drawable/closeimage"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/user_name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
<EditText
android:id="#+id/feed_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#null"
android:ellipsize="end"
android:fontFamily="san-serif-condensed"
android:padding="12dp"
android:singleLine="true"
android:text="sherry's phone"
android:textColor="#android:color/black"
android:textSize="#dimen/feed_name_size"
android:visibility="gone" />
<TextView
android:id="#+id/feed_user_name_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#null"
android:ellipsize="end"
android:fontFamily="san-serif-condensed"
android:padding="12dp"
android:paddingLeft="20dp"
android:singleLine="true"
android:text="sherry's phone"
android:textColor="#android:color/black"
android:textSize="#dimen/feed_name_size" />
<ImageView
android:id="#+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:scaleType="centerInside"
android:src="#drawable/editname" />
<Button
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_corner_update_block"
android:fontFamily="san-serif-medium"
android:text="Done"
android:textColor="#android:color/white"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
2)android:windowSoftInputMode="adjustResize" in your manifest.xml
3) disable scroll in java code (optional)
mScrollView.setOnTouchListener( new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
});
I have designed the login layout as follows
<?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="#drawable/login_bg">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="#+id/login_fields_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<ImageView
android:id="#+id/loginLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="30dp"
android:src="#drawable/logo" />
<EditText
android:id="#+id/userNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:background="#drawable/textfield"
android:drawableLeft="#drawable/username"
android:drawablePadding="10dip"
android:hint="#string/hint_username"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLength="50"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/login_textcolor"
android:textCursorDrawable="#null" />
<EditText
android:id="#+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#drawable/textfield"
android:drawableLeft="#drawable/password"
android:drawablePadding="10dip"
android:hint="#string/hint_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:padding="10dp"
android:singleLine="true"
android:textColor="#color/login_textcolor"
android:textCursorDrawable="#null" />
<LinearLayout
android:id="#+id/loginOptionsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<CheckBox
android:id="#+id/rememberMeCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:checked="false"
android:drawableEnd="#drawable/bg_checkbox"
android:gravity="center_vertical"
android:paddingRight="40dp"
android:text="#string/text_rememberme"
android:textColor="#color/login_textcolor"
android:textSize="14sp" />
<Button
android:id="#+id/forgotPasswordButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#null"
android:gravity="right|center_vertical"
android:singleLine="true"
android:text="#string/text_forgotpassword"
android:textColor="#color/login_textcolor"
android:textSize="14sp" />
</LinearLayout>
<Button
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#drawable/button_bg"
android:text="#string/text_login"
android:textColor="#android:color/white"
android:textSize="20dp"
android:textStyle="bold" />`
</LinearLayout>
</ScrollView>
</RelativeLayout>
when the i touched on the edittext the background is moving up it need to be constant as it is outside the scrollview.How to solve this issue.
i have referred the following
Background Image Placement
as in this they need in the bottom corner i need it as background.but anyway with curiosity i tried it but still it is scrolling the background
I tried it and it works. Remove the background from xml layout
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getWindow().setBackgroundDrawableResource(R.drawable.login_bg) ;
Use the following in your activity
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
I'm learning about Layout managers to improve my app design. For the most part it worked out ok. The only thing I want is my buttons to be positioned a little higher.I can achieve this by removing the 3 buttons from the layout manager but by doing this I have issues on lower res devices. (The buttons will position themselves over the EditText fields or position themselves over my ad at the bottom). I've tried some things I found online but I only ended up ruining the layout.
Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/textviewLayoutLeft"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvPpl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:text="Price Per Liter"
android:textStyle="bold" />
<TextView
android:id="#+id/tvAvgConsumption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="avg(l/100km)"
android:textStyle="bold" />
<TextView
android:id="#+id/tvDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Distance (km)"
android:textStyle="bold" />
<TextView
android:id="#+id/tvAmountOfPersons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="# Persons"
android:textStyle="bold" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:text="Price Per Person"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/textfieldLayoutRight"
android:layout_width="166dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/textPrijsPerLiter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/textVerbruik"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/textAfstand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/textAantalPersonen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:imeOptions="actionGo"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/textViewPPP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffff000f"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<Button
android:id="#+id/btnBereken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Calculate"
android:textStyle="bold" />
<Button
android:id="#+id/btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset all textfields"
android:textStyle="bold" />
<Button
android:id="#+id/btnLoad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load latest results"
android:textStyle="bold" />
</LinearLayout>
<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="MY_ID" />
</LinearLayout>
</RelativeLayout>
You can:
Give up second linear layout and move button layout and ad layouts to main layout. Stick ad layout to bottom and declare it BEFORE button layout. Set buttons adjustments to layout_below="textfieldlayout" and layout_above="ad" instead of layout_alignParentBottom="true".
Consider using linear layout with weightSum. Every parent layout should have weightSum=100, every child will respectively have % of space. From my point of view this way would be the best, because views will position equally for merely all devices and even layout tree depth will remain the same. You'll only have to change the parent layout to LinearLayout and set weights.
With my layout, I would like the EditTexts to fill all of the horizontal space on their row, but leave the remaining space for a button to its right.
I would also like the buttons to be aligned to the bottom of the EditText that is on its row.
Currently, the buttons are not aligned to the bottom of their EditText, and I would like to know how I can achieve this.
Here is a screenshot:
And here is my XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp" >
<LinearLayout
android:id="#+id/nameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/nameEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:ems="8"
android:textSize="15sp"
android:hint="enter name" />
<ImageButton
android:id="#+id/micNameButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_mic" />
</LinearLayout>
<LinearLayout
android:id="#+id/editLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/nameLayout">
<EditText
android:id="#+id/notesEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:ems="8"
android:textSize="15sp"
android:hint="enter notes" />
<ImageButton
android:id="#+id/micNotesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_mic" />
</LinearLayout>
</RelativeLayout>
Try keeping your margin attributes in the LinearLayout, and not in the actual EditText or ImageButton. And set the gravity of the layout to bottom.
(Edit: Also notice that I added android:orientation="horizontal" to the LinearLayouts. You should always have an orientation when child views use layout_weight)
It should look something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp" >
<LinearLayout
android:id="#+id/nameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:gravity="bottom" >
<EditText
android:id="#+id/nameEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ems="8"
android:textSize="15sp"
android:hint="enter name" />
<ImageButton
android:id="#+id/micNameButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_mic" />
</LinearLayout>
<LinearLayout
android:id="#+id/editLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:gravity="bottom"
android:layout_below="#+id/nameLayout">
<EditText
android:id="#+id/notesEditText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:ems="8"
android:textSize="15sp"
android:hint="enter notes" />
<ImageButton
android:id="#+id/micNotesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_mic" />
</LinearLayout>
</RelativeLayout>