Android Create aligned fields Layout - android

Here's my issue I have a login and want to line up the EditText fields. See the mockup picture attached .
I have tried a few ways and cannot figure out how to make the fields lineup.
I really hate layouts in Android I spend more time just messing with things to line up right. Wish they would just scrap it and use something more intuitive, as its more like using tables in HTML. So in advance thanks for your help and cheers!

You could probably play around with RelativeLayout and get just what you want.
Here's an approximation with TableLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_marginTop="40dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="10dip"
android:text="UserID:" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="USER ID" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="10dip"
android:text="Password:" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="PASSWORD" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_marginTop="50dip"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:gravity="center">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="LOGIN" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="REGISTER" />
</LinearLayout>
</LinearLayout>

See if this works for you. It doesnt center quite perfectly but it does align well across multiple screen sizes.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#FFFF0000">
<LinearLayout android:id="#+id/top_row"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_marginTop="25dip">
<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content" android:text="User Id" android:gravity="right" android:layout_marginRight="10dip" android:layout_width="fill_parent" android:layout_weight="2" android:textColor="#FF000000"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:ems="10" android:layout_weight="1"></EditText>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content" android:text="Password" android:gravity="right" android:layout_marginRight="10dip" android:layout_width="fill_parent" android:layout_weight="2" android:textColor="#FF000000"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:ems="10" android:layout_weight="1"></EditText>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_below="#+id/top_row" android:layout_centerHorizontal="true" android:layout_marginTop="20dip">
<Button android:layout_width="wrap_content" android:text="LOGIN" android:layout_height="wrap_content" android:layout_marginRight="10dip"></Button>
<Button android:text="REGISTER" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="10dip"></Button>
</LinearLayout>
</RelativeLayout>
Here's what it looks like in my IDE...

You can do this quick and dirty using TableLayout, just add a TableRow with a TextView and a EditText for the userid and repeat the same for the password.
See http://developer.android.com/resources/tutorials/views/hello-tablelayout.html

Related

Not happy with my Android UI layout

I am having a heck of time trying to get my UI to look the way I want. Here's what I've got ...
I would like the TextView, the XX:XX:XX, text font to be larger and centered between the EditText and Button. Also how come the user gets the phone keyboard instead of a qwerty keyboard to use to enter text?
Here's my layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.2"
android:text="#string/add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Use the following code to achieve what you want:......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18dp"
android:layout_weight="1"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
please refer this xml all the changes is done tested is also done.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:textSize="18dp"
android:layout_weight="1"
android:text="hello" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
You can use relative layout to do that. You can change the font size with android:textSize
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/new_bookmark_name"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="#string/xx_xx_xx" />
<Button
android:id="#id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/add"/>
</RelativeLayout>
Replace android:layout_gravity="center" by
android:gravity="center" in your TextView.
and regarding the keyboard layout, it looks like you are trying in the emulator. The emulator shows up 12pad keyboard in portrait mode. You can try in the device.
Please follow below, i have made a sample UI exactly what you have asked for using Relative Layout and by using minimum number of lines. Please have a look and check if can solve the purpose. I have also attached snapshot for the same.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:padding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/ed_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="number" />
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ed_name"
android:text="XX:XX:XX"
android:textSize="18dp" />
<Button
android:id="#+id/btn_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text=" add " />
</RelativeLayout>
</RelativeLayout>
About the keypad :Check it on actual device , the device will open its own default keypad.

Align two imageView with textView XML in android

I have a problem with my xml for android.
I have this layout to use it in each line of a Listview (that works fine).
I want to put two lines (head and body) of text, and align Right of the first line I have to put two ImageView. (Also have first of all a hidden textView)
Something like this:
My problem is when I try to put both imageViews (with only one it shows fine, but with two don't show nothing).
this is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/TvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/new_messages" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/new_group" />
</LinearLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
sorry for my english and thank you in advance!
If I am understanding correctly then I believe this should be close to what you are looking for:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/TvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Test"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:src="#drawable/new_messages" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/ImgNewConvGroup"
android:gravity="right"
android:src="#drawable/new_group" />
</RelativeLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
Try it out and let me know if that works for you, I changed the inner layout from LinearLayout to RelativeLayout and created what I believe you are looking for in relational locations.
Note: Be cautious of your TextView extending far enough to go behind the ImageViews, if that happens then it might be better to (set for the ImageViews):
android:layout_below="#+id/TvName"
on both and remove:
android:layout_centerVertical="true"
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TV"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="visible" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TvName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="TVName"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="right"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="right"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TVDescription"
android:textSize="22sp"
android:textStyle="normal" />
Take a look if is what are you looking for.
Is a lot of code just will write the structure
<LinearLayout android:orientation="vertical">
<LinearLayout android:orientation="horizontal">
<LinearLayout android:orientation="horizontal">
<TextView/>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:gravity="right">
<ImageView/>
<ImageView/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:orientation="vertical">
<TextView/>
</LinearLayout>
</LinearLayout>

Why edit text preview is not showing properly....?

I have an edit text which is showing preview as in the following image.
While I am entering the input, only half it is showing.After pressing back(soft keyboard dissappear) that time showing full text.
code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#D8D8D8" android:orientation="vertical"
android:padding="10dp" android:gravity="center" android:layout_gravity="center">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="Register Now" android:id="#+id/textView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textStyle="bold" android:gravity="center" android:textSize="30dp">
</TextView>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingLeft="20dp" android:paddingRight="20dp"
android:orientation="vertical" android:gravity="center">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:text=" First Name" android:id="#+id/textView1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:textSize="17dp"
android:textColor="#6E6E6E"></TextView>
<EditText android:layout_width="fill_parent"
android:layout_height="55dp" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:id="#+id/fname"
android:singleLine="true" android:paddingLeft="10dp"
android:paddingRight="10dp" android:background="#drawable/edit_bg"></EditText>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:text=" Last Name" android:id="#+id/textView1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:textSize="17dp"
android:textColor="#6E6E6E"></TextView>
<EditText android:layout_width="fill_parent"
android:layout_height="55dp" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:id="#+id/lname"
android:singleLine="true" android:paddingLeft="10dp"
android:paddingRight="10dp" android:background="#drawable/edit_bg"></EditText>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_marginBottom="10dp">
<TextView android:text=" Email" android:id="#+id/textView1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:textSize="17dp"
android:textColor="#6E6E6E"></TextView>
<EditText android:layout_width="fill_parent"
android:layout_height="55dp" android:id="#+id/email"
android:paddingLeft="10dp" android:paddingRight="10dp"
android:background="#drawable/edit_bg" android:inputType="textEmailAddress"
android:singleLine="true"></EditText>
</LinearLayout>
<RelativeLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="80dp">
<Button android:text="Register" android:id="#+id/register"
android:layout_width="200dp" android:layout_height="wrap_content"
android:layout_centerInParent="true" android:textStyle="bold"></Button>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
How to fix this problem...?
Thanks in advance...!
problem is in your layout design. you checked in low res screen.
Alcate OT-890 - 320 x 240 pixels, 2.8 in
Samsung GT-i5801 -240 x 400 px (3,2")
can u add android:windowSoftInputMode="adjustResize" in your android manifest file of your activity.
//while keyboard is sliding/showing your are getting problem.
so remove the relative layout and try this below line.
<LinearLayout android:id="#+id/linearLayout1" android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent" android:layout_height="80dp">
<Button android:text="Register" android:id="#+id/register"
android:layout_width="200dp" android:layout_height="wrap_content"
android:textStyle="bold"></Button>
</LinearLayout>
Maybe if you make the text inside a bit smaller the text will fit in.
Another idea is to remove padding if you have any inside the textview, or increase it's height.
Not just a problem with the emulator? Have you tried a real device?
I tried the following on an actual device, works perfectly.
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text=" Email"
android:textColor="#6E6E6E"
android:textSize="17dp" >
</TextView>
<EditText
android:id="#+id/email"
android:background="#drawable/edit_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:singleLine="true" />
</LinearLayout>
set height of edittext as android:layout_height="200dp" or some value and check once.

Android linear layout align center and right

This is what I have:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#FFFFFF">
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#E30000"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="#+id/TextView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"
android:text="Something"
android:gravity="right|center_vertical"
/>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="right|center_vertical"
android:layout_gravity="center_vertical"
android:background="#E30000">
<Button
android:id="#+id/btnCalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/icon"
android:gravity="right|center_vertical"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And I want this:
So horizontal center align the text and vertical center align the button.
What am I missing? I haven't tried RelativeLayout and I would prefer LinearLayout to work this out.
android:gravity="right|center_vertical"
aligns your TextView to the right. How about center_horizontal?
And your LinearLayouts have the same ID, if there is not more code, then I would delete one of them.
try this one
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#FFFFFF">
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#E30000"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_vertical">
<TextView
android:id="#+id/TextView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"
android:text="Something"
android:layout_weight="1"
android:gravity="center"/>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="right|center_vertical"
android:layout_gravity="center_vertical"
android:background="#E30000"
android:layout_width="wrap_content">
<Button
android:id="#+id/btnCalls"
android:layout_width="wrap_content"
android:drawableLeft="#drawable/icon"
android:gravity="right|center_vertical"
android:layout_height="wrap_content"
android:layout_margin="5dip"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I found none of the answers work exactly as the OP intended, but the RelativeLayout solution was the closest one. Except that the TextView wasn't centered. But, with layout_centerInParent=true, works like a charm:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TextView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"
android:text="Something"
android:layout_centerInParent="true" />
<Button
android:id="#+id/btnCalls"
android:drawableLeft="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
you have used android:gravity="right|center_vertical" in your textview. Use android:gravity="center".
Try to add empty View inside horizontal LinearLayout between element that you want see left and element that you want to see right, e.g.:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
define layout weight for TextView and LinearLayout
set android:layout_weight="1" to TextView
set android:layout_weight="0" to LinearLayout
and also change the layout_width="wrap_content" to LinearLayout
and set layout_gravity="center" to TextView
I think,gravity means the position of things inside the component(for textview,it means the text you have given)in component where layout_gravity means position of component itself in the whole layout.So...
Try Using:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#FFFFFF"
>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#E30000"
android:layout_gravity="right"
android:gravity="center_vertical|right"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:gravity="center_vertical|center"
android:layout_weight="0.9"
>
<TextView
android:id="#+id/TextView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"
android:text="Something"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal|center_vertical"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:gravity="center_vertical|right"
android:paddingTop="5dip"
android:layout_weight="0.1"
>
<Button
android:id="#+id/btnCalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/icon"
android:layout_gravity="center_vertical"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Just use RelativeLayout, and wallaaa!!!
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TextView00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textSize="20px"
android:textStyle="bold"
android:text="Something"
android:gravity="center" />
<Button
android:id="#+id/btnCalls"
android:drawableLeft="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
The solution for this is-
android:gravity="center_vertical"
Normally you'll also have to take care of its parent's position too to make sure it works.

Android textview and Menu

i have a textview and a Menu , the textview is currently showing at the bottom of the screen and when menu pressed ,currently the menu hide the textview ,but i want the textview automatically move upwords so that everybody can see
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:background="#drawable/android_bg"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/navigationbar">
<TextView android:layout_width="wrap_content" android:layout_centerInParent="true"
android:id="#+id/banner_text"
android:layout_height="wrap_content" android:background="#drawable/bannertext_angies_list">></TextView>
<Button
android:layout_width="55dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_height="35dp"
android:background="#drawable/sign_out_button_clicked_button"
android:id="#+id/signout"/>
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<TextView
android:visibility="gone"
android:textColor="#000000"
android:text="Thank you, your report has been"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="260dp"
android:layout_height="fill_parent"
android:id="#+id/Thanks_to_submission1"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:visibility="gone"
android:paddingLeft="70dp"
android:textColor="#000000"
android:text="submitted successfuly!"
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="260dp"
android:layout_height="fill_parent"
android:id="#+id/Thanks_to_submission2"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp">
<Button
android:layout_width="260dp"
android:layout_height="fill_parent"
android:background="#drawable/submitbutton"
android:id="#+id/submitreport_providertype_button"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<Button
android:layout_width="260dp"
android:layout_height="fill_parent"
android:background="#drawable/searchlist_button"
android:id="#+id/search_list_button"/>
</TableRow>
<TableRow
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp">
<Button
android:layout_width="260dp"
android:layout_height="fill_parent"
android:background="#drawable/bigdeal_button"
android:id="#+id/big_deal_button"/>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="50dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:onClick="true"
android:textColor="#000000"
android:text="Or visit our website at" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/link"
android:gravity="center_vertical"
android:autoLink="web"
android:linksClickable="true"
android:layout_gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:onClick="true"
android:textColor="#000000"
android:text="#string/link" />
</LinearLayout>
<TextView
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="Or visit our website at" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
That's not really supported by Android, and it's by design. The idea is that you can use the full screen for your UI, and the menu takes up part of the space when you need to select it. You don't want to worry about text views and other things while the menu is up. This is better than the iPhone, where you permanently have to give up screen space for menu items. If something is really important, then move it away from the bottom of the screen.
If you're really bent on moving stuff around, you could intercept Activity.onPrepareOptionsMenu and move things around in your UI, although the function wasn't really meant for that purpose. Then matching call is onOptionsMenuClosed.

Categories

Resources