I have a linearlayout with a textview, and edittext. How do I center the text within edittext. It appears to be drawn to the bottom as shown below.I want it to be consistent with the baseline similar to that of the textview to its left.
The layout code is as below:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="75dp"
android:layout_height="30dp"
android:ems="10"
android:textAlignment="center"
android:text="NAME"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/tv_name"
android:background="#drawable/orange_left_rounded_corner"
/>
<EditText
android:layout_width="125dp"
android:layout_height="30dp"
android:ems="10"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:text=""
android:layout_gravity="right"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/et_name"
android:background="#drawable/orange_right_rounded_corner"
/>
</LinearLayout>
Use android:gravity="center" to have the input be centered
Just do that
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="75dp"
android:layout_height="30dp"
android:ems="10"
android:textAlignment="center"
android:text="NAME"
android:textColor="#FFFFFF"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/tv_name"
android:background="#drawable/orange_left_rounded_corner"
android:gravity="center_vertical"
/>
<EditText
android:layout_width="125dp"
android:layout_height="30dp"
android:ems="10"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:text=""
android:layout_gravity="right"
android:gravity="center_horizontal"
android:textColor="#000000"
android:textSize="16sp"
android:singleLine="true"
android:id="#+id/et_name"
android:background="#drawable/orange_right_rounded_corner"
/>
Try with this 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="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_name"
android:layout_width="75dp"
android:layout_height="30dp"
android:background="#drawable/orange_left_rounded_corner"
android:ems="10"
android:gravity="center_vertical"
android:singleLine="true"
android:text="NAME"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<EditText
android:id="#+id/et_name"
android:layout_width="125dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:background="#drawable/orange_right_rounded_corner"
android:ems="10"
android:gravity="center_horizontal"
android:singleLine="true"
android:text=""
android:textAlignment="center"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
Related
small problem here:
This is my code of the layout in question:
<LinearLayout
android:orientation="horizontal"
android:layout_weight="100"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:layout_gravity="center">
<EditText
android:background="#00000000"
android:singleLine="true"
android:maxLength="2"
android:inputType="number"
android:gravity="bottom"
android:hint="00"
android:textColorHint="#2f8677"
android:textColor="#2f8677"
android:textSize="40sp"
android:id="#+id/txtMinutes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:gravity="top"
android:layout_gravity="top"
android:text=":"
android:textSize="40dp"
android:textColor="#2f8677"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:background="#00000000"
android:singleLine="true"
android:maxLength="2"
android:inputType="number"
android:gravity="bottom"
android:hint="00"
android:textColorHint="#2f8677"
android:textColor="#2f8677"
android:textSize="40sp"
android:id="#+id/txtSeconds"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="center"
android:text=":"
android:textSize="40dp"
android:textColor="#2f8677"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:background="#00000000"
android:singleLine="true"
android:maxLength="2"
android:inputType="number"
android:gravity="bottom"
android:hint="00"
android:textColorHint="#2f8677"
android:textColor="#2f8677"
android:textSize="40sp"
android:id="#+id/txtTimerMicroSeconds"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
This is the result:
Why are the ":" sitting on the bottom and the EditTexts are on top? Both are (obviously) supposed to be on the same hight :(
Another little thing: See that little bar to the left of the first EditText? It is there because this is an edit text and you can "type" things into it. But I don't want it to show- How do I get this to go away?
I see some issues in your android:gravity, you can use android:gravity="center_vertical" to align your widgets with each other.
See the result here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="100"
android:gravity="center_horizontal"
android:orientation="horizontal">
<EditText
android:id="#+id/txtMinutes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center_vertical"
android:hint="00"
android:inputType="number"
android:maxLength="2"
android:singleLine="true"
android:textColor="#2f8677"
android:textColorHint="#2f8677"
android:textSize="40sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="center_vertical"
android:text=":"
android:textColor="#2f8677"
android:textSize="40dp" />
<EditText
android:id="#+id/txtSeconds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center_vertical"
android:hint="00"
android:inputType="number"
android:maxLength="2"
android:singleLine="true"
android:textColor="#2f8677"
android:textColorHint="#2f8677"
android:textSize="40sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=":"
android:textColor="#2f8677"
android:textSize="40dp" />
<EditText
android:id="#+id/txtTimerMicroSeconds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center_vertical"
android:hint="00"
android:inputType="number"
android:maxLength="2"
android:singleLine="true"
android:textColor="#2f8677"
android:textColorHint="#2f8677"
android:textSize="40sp" />
</LinearLayout>
Use below code:
I have removed layout_top from textview for alignment.
And you may use android:cursorVisible="false" to hide edittext cursor.
If you do not want to allow editing, then use textview instead of Edittext
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="100"
android:gravity="center"
android:layout_gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:background="#00000000"
android:singleLine="true"
android:maxLength="2"
android:inputType="number"
android:gravity="bottom"
android:hint="00"
android:cursorVisible="false"
android:textColorHint="#2f8677"
android:textColor="#2f8677"
android:textSize="40sp"
android:id="#+id/txtMinutes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:gravity="top"
android:text=":"
android:textSize="40dp"
android:textColor="#2f8677"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:background="#00000000"
android:singleLine="true"
android:maxLength="2"
android:inputType="number"
android:gravity="bottom"
android:hint="00"
android:cursorVisible="false"
android:textColorHint="#2f8677"
android:textColor="#2f8677"
android:textSize="40sp"
android:id="#+id/txtSeconds"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="center"
android:text=":"
android:textSize="40dp"
android:cursorVisible="false"
android:textColor="#2f8677"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:background="#00000000"
android:singleLine="true"
android:maxLength="2"
android:inputType="number"
android:gravity="bottom"
android:hint="00"
android:textColorHint="#2f8677"
android:textColor="#2f8677"
android:textSize="40sp"
android:id="#+id/txtTimerMicroSeconds"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
I have a main_activity.xml that is displaying a fragmented layout. The layout contains imageview (a logo), and some text fields. At first, I tried to use relativelayout, it looks awesome/perfect on the design view. But when run on the emulater, everything jumble up. So I decided to use a LinearLayout. After changing, there's an improvement in the UI. But the problem is the image is not displaying.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout02">
<ImageView
android:id="#+id/imageView"
android:layout_width="276dp"
android:layout_height="276dp"
app:srcCompat="#drawable/splash_logob"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPersonName"
android:text=""
android:hint="URL"
android:ems="10"
android:id="#+id/siteurl"
android:height="24sp"
android:layout_gravity="center"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:textAlignment="viewStart" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPassword"
android:text=""
android:hint="Password"
android:ems="10"
android:id="#+id/password"
android:height="24sp"
android:layout_gravity="center"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:layout_marginTop="17dp" />
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="276dp"
android:inputType="textPersonName"
android:hint="username"
android:ems="10"
android:id="#+id/username"
android:height="24sp"
android:layout_gravity="center"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:gravity="center"
android:paddingTop="3dp"
android:layout_centerHorizontal="true"
android:paddingLeft="5dp"
android:layout_marginTop="17dp" />
</RelativeLayout>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:textColor="#color/textcolor"
android:id="#+id/scannedresult"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/scanbtn"
android:layout_alignStart="#+id/scanbtn" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_height="wrap_content"
android:textColor="#color/textcolor"
android:text="QR Scanner"
android:id="#+id/scanbtn"
android:layout_width="wrap_content"
android:layout_alignRight="#+id/secretkey"
android:layout_alignEnd="#+id/secretkey"
android:layout_below="#+id/secretkey"
android:layout_alignBottom="#+id/login"
android:layout_weight="1" />
<Button
android:text="Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="do_login"
android:layout_below="#+id/secretkey"
android:layout_alignLeft="#+id/secretkey"
android:layout_alignStart="#+id/secretkey"
android:id="#+id/login"
android:layout_weight="1" />
</LinearLayout>
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:text=""
android:hint="Secret Key"
android:height="24sp"
android:ems="10"
android:id="#+id/secretkey"
android:background="#color/input_color"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:paddingLeft="5dp"
android:layout_marginTop="17dp"
android:layout_below="#+id/password"
android:layout_alignLeft="#+id/password"
android:layout_alignStart="#+id/password"
android:layout_alignRight="#+id/password"
android:layout_alignEnd="#+id/password" />
The problem is when i run, it did not display the image logo. What is wrong?
Screenshot
use:
android:src="#drawable/splash_logob"
instead of:
app:srcCompat="#drawable/splash_logob"
srcCompat attribute is defined within AppCompat library.
Change your imageview like this
<ImageView
android:id="#+id/imageView"
android:layout_width="276dp"
android:layout_height="276dp"
android:src="#drawable/splash_logob"
android:layout_centerHorizontal="true"
/>
I have set width of all the components to wrap_content in MainActivity but wrap_content does not works, I mean when I type into EditText then text appears only in limited width.
I want the TextViews and EditTexts to expand their widths according to input text length.
Please help, what is issue with my code?
MainActivity XML:
<?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: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.example.appdeveloper.appname.MainActivity"
android:background="#ff003b"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/appLogoImage_id"
android:src="#drawable/applogo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="You Can't Proceed Without Inserting Primary Sim (SIM-1) In Your Device!"
android:id="#+id/regNoSim_id"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textAlignment="center"
android:textColor="#ffffff"
android:visibility="invisible"
android:layout_below="#+id/appLogoImage_id"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="REGISTRATION"
android:id="#+id/regTitle_id"
android:layout_below="#+id/appLogoImage_id"
android:textColor="#ffffff"
android:textAlignment="center"
android:layout_marginTop="50dp"
android:visibility="invisible"
android:textStyle="bold"
android:layout_centerHorizontal="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/loginPassword_id"
android:overScrollMode="never"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|text"
android:ems="10"
android:id="#+id/regName_id"
android:hint="Your Name"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="0dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regPassword_id"
android:layout_below="#+id/regName_id"
android:hint="Application Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regVerifyPass_id"
android:layout_below="#+id/regPassword_id"
android:hint="Verify Password"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regRingCode_id"
android:hint="Ringing Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regVerifyPass_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/regLocationCode_id"
android:hint="Location Codeword"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regRingCode_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum1_id"
android:hint="1st Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regLocationCode_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum2_id"
android:hint="2nd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum1_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/regNum3_id"
android:hint="3rd Trusted Number"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum2_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/regEmail_id"
android:hint="Email Address"
android:textAlignment="center"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:background="#android:color/transparent"
android:layout_below="#+id/regNum3_id"
android:layout_marginTop="10dp"
android:textCursorDrawable="#drawable/white_cursor"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="230dp"
android:layout_height="wrap_content"
android:text="Register"
android:id="#+id/regButton_id"
android:visibility="invisible"
android:layout_centerHorizontal="true"
android:layout_below="#+id/regEmail_id"
android:layout_marginTop="15dp"
android:layout_marginBottom="20dp" />
</RelativeLayout>
</ScrollView>
<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/loginPassword_id"
android:textAlignment="center"
android:hint="Enter Application Password"
android:textColor="#ffffff"
android:textColorHint="#000000"
android:layout_below="#+id/appLogoImage_id"
android:layout_marginTop="50dp"
android:background="#android:color/transparent"
android:visibility="invisible"
android:textCursorDrawable="#drawable/white_cursor"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Forgotten Password?"
android:id="#+id/forgottenPass_id"
android:textAlignment="center"
android:textColor="#ffffff"
android:visibility="invisible"
android:layout_below="#+id/loginPassword_id"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:minHeight="30dp" />
</RelativeLayout>
Its because you have set android:ems="10" and that's the limitation remove it and see the difference!
You are thinking it's wrapped and adjust it's size because of your wrap_content but you have set android:ems !
Makes the TextView be exactly this many ems wide.
Refer : https://developer.android.com/reference/android/widget/TextView.html#attr_android:ems
I am developing an android application. On the preview the view is presanting the way I have set it but when I run it on a device I am seeing spaces on it right and left side.
Screen shots are attached for the better understanding of the problem.
Below is the code of my layout.
<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"
tools:context="------"
>
<!-- TODO: Update blank fragment layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView"
android:scrollbars="none"
android:layout_gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/screen_background">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/telephone_number"
android:id="#+id/telephonNumberTextView"
android:phoneNumber="false"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/phoneNumberEditText"
android:layout_weight="1"
android:clickable="true"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:textAlignment="textStart" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/telephone_extension"
android:id="#+id/telephoneExtensionTextView"
android:layout_marginTop="10dp"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/telephoneExtensionEditText"
android:background="#drawable/edittext"
android:singleLine="true"
android:paddingLeft="4dp"
android:layout_weight="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/email_id"
android:id="#+id/emailIdTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailIdEditText"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:layout_weight="1"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_margin="5dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/problem_type"
android:id="#+id/problemTypeTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="#string/fetch_problem_types"
android:id="#+id/button"
android:background="#drawable/buttonback"
android:textColor="#android:color/white"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/location"
android:id="#+id/locationTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="#+id/locationEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/brief_desc"
android:id="#+id/briefDescTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/briefDescEditText"
android:singleLine="true"
android:layout_gravity="bottom"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/doc_desc"
android:id="#+id/docDescTextView"
android:layout_gravity="left|center_vertical"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/docDescEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/approval_memo"
android:id="#+id/approvalMemoTextView"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:textColor="#android:color/white"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/approvalMemoEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:paddingLeft="4dp"
android:layout_weight="1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/requester_Name"
android:id="#+id/requesterNameTextView"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="10dp"
android:textColor="#android:color/white"
android:layout_marginBottom="5dp"
android:paddingLeft="2dp"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/requesterNameEditText"
android:layout_gravity="bottom"
android:singleLine="true"
android:background="#drawable/edittext"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:paddingLeft="4dp"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="#string/submit_button_title"
android:id="#+id/submitButton"
android:layout_gravity="center_vertical"
android:background="#drawable/buttonback"
android:textColor="#android:color/white"
android:layout_marginTop="10dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="5dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
The problem (most probably) lies in the top level XML. I assume you posted only the content.xml which is included my activity_main.xml, because I can't see the Floating Action Button.
I guess you used the build-in generator to create layouts for you and edited the content.xml one. The paddings are defined inside the activity_main.xml one. Delete them and you are good to go.
Remove layout android:layout_margin="5dp" in Email Id EditText
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailIdEditText"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:layout_weight="1"
android:background="#drawable/edittext"
android:paddingLeft="4dp" />
I really hope somebody can help me here because I am going to start pulling my hair out if this keeps doing what it's doing.
I'm trying to design a layout and I want all of my stuff to be centered. So far, everything is. However, the Save button I created will not center itself for the life of it. It consistently aligns its left edge with the center of the screen, rather than the center of the button itself.
Below is a screenshot of my simple design and the xml behind it... Any help will be GREATLY appreciated!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_settings"
tools:context="com.hypertom.weeklymealgenerator.SettingsActivity"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/strSettingsTitle"
android:id="#+id/textView"
android:textIsSelectable="false"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/textView2" />
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsNumMeals"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginTop="40dp"
android:layout_marginLeft="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsThresholdMin"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_alignEnd="#+id/textView2"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsThresholdMax"
android:id="#+id/textView4"
android:layout_below="#+id/textView3"
android:layout_alignEnd="#+id/textView3"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsNumServings"
android:id="#+id/textView5"
android:layout_below="#+id/textView4"
android:layout_alignEnd="#+id/textView4"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/strSettingsNumSubstitutes"
android:id="#+id/textView6"
android:layout_below="#+id/textView5"
android:layout_alignEnd="#+id/textView5"
android:layout_marginTop="10dp"
android:gravity="right"
android:textSize="18sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnSettingsSave"
android:id="#+id/button4"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="200dp" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText"
android:layout_alignBottom="#+id/textView2"
android:layout_toEndOf="#+id/textView2"
android:layout_marginBottom="-12dp"
android:textSize="18sp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText2"
android:layout_alignBottom="#+id/textView3"
android:layout_alignStart="#+id/editText"
android:textSize="18sp"
android:layout_marginBottom="-12dp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText3"
android:layout_above="#+id/textView5"
android:layout_alignStart="#+id/editText2"
android:layout_marginBottom="-12dp"
android:textSize="18sp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText4"
android:layout_above="#+id/textView6"
android:layout_alignStart="#+id/editText3"
android:textSize="18sp"
android:layout_marginBottom="-12dp"
android:gravity="center" />
<EditText
android:layout_width="65dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText5"
android:layout_alignBottom="#+id/textView6"
android:layout_alignStart="#+id/editText4"
android:layout_marginBottom="-12dp"
android:textSize="18sp"
android:gravity="center" />
</RelativeLayout>
Something like this ? It can be done much easier in LinearLayout though.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="strSettingsTitle"
android:layout_marginTop="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textIsSelectable="false"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:id="#+id/linearlayout">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="10dp"
android:layout_centerInParent="true">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="# of Meals"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/textView2"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="Threshold Min"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/textView3"
android:layout_marginTop="10dp"
android:gravity="right"
android:text="Threshold Max"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/textView4"
android:gravity="right"
android:layout_marginTop="10dp"
android:text="Num of Servings"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="30dp"
android:layout_below="#+id/textView5"
android:layout_marginTop="10dp"
android:text="Num of Substitutes"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="10dp">
<EditText
android:id="#+id/editText"
android:layout_width="65dp"
android:layout_height="30dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText2"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/editText"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText3"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_below="#+id/editText2"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText4"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_below="#+id/editText3"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
<EditText
android:id="#+id/editText5"
android:layout_width="65dp"
android:layout_height="30dp"
android:layout_below="#+id/editText4"
android:layout_marginTop="10dp"
android:ems="10"
android:inputType="number"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_centerInParent="true"
android:layout_below="#+id/linearlayout"
android:text="Save" />
</RelativeLayout>