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.
Related
The problem is with the textview which has the id editTextLabelID as shown below in the code.
I am trying to have a layout designed as follows: label:editText
What I have in the xml layout is, a Relativelayout with green background. And inside it, there is a textview which should be my label and next to it horizontally, there should be an edittext
the problem is, according to the below code, I receive the the below result shown in the image. And the edittext, although it precedes the textview in the xml layout, however it shadows it. how to place both of the textview and edittext horizontally right after each other?
UPDATED
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/titleBackGroundColor">
<RelativeLayout
android:id="#+id/RelativeLayout00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center_horizontal">
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor">
</TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text">
</EditText>
</RelativeLayout>
</LinearLayout>
UPDATED
Results:
Try This :
<?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:orientation="horizontal">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
</RelativeLayout>
you are missing these 3 lines in your edit text
android:layout_width="match_parent"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentTop="true"
if you don't put it to match parent, it will be very small
the ems value is not a good use here usually
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/marginTop"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor">
</TextView>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_alignParentTop="true"
android:inputType="text">
</EditText>
</RelativeLayout>
</LinearLayout>
// try this way,hope this will help you...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bodyBackGroundColor">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/labelsTextSizes"
android:textColor="#color/contentsColor"/>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
</LinearLayout>
in your code, you have many non-usefull layouts, simply you can do it like this :
<TextView
android:id="#+id/addLocationActivityTitleID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="#dimen/titlesTextSize"
android:text="#string/addLocationActivityTitle"
android:textColor="#color/titleColor"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ff00">
<TextView
android:id="#+id/editTextLabelID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/labelsTextSizes"
android:layout_alignParentLeft="true"
android:layout_marginLeft="4dp"
android:textColor="#color/contentsColor"/>
<EditText
android:id="#+id/editTextID"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/editTextLabelID"
android:layout_marginLeft="4dp"
android:layout_alignTop="#+id/editTextLabelID"
android:layout_alignBottom="#+id/editTextLabelID"
android:layout_width="match_parent"
android:ems="10"
android:inputType="text"/>
</RelativeLayout>
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.
how do i align spinner to show equal in width in all screen? in my code spinner show different width in different screen what do i do? i have given fixed length
android:layout_marginRight="45dp"
android:layout_marginLeft="45dp"
in edittext and spinner but spinner show diffrent width in diffrent screen how do i fix this issue? i this is my image of screen http://imgur.com/RtWNgNI
and below is my full source code of screen.
<?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="#000000"
android:orientation="vertical"
android:weightSum="6" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="55dp"
android:layout_weight="0.5"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:src="#drawable/agappbg" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="1" >
<EditText
android:id="#+id/txtMobileNo"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="left"
android:hint="#string/MobileNo"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="1" >
<EditText
android:id="#+id/txtPinNo"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="left"
android:hint="#string/PinNo"
android:inputType="textPassword"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:orientation="horizontal"
android:weightSum="1" >
<Spinner
android:id="#+id/lgnspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-17dp"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_marginTop="-15dp"
android:layout_weight="1"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:prompt="#string/network_prompt" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:orientation="horizontal"
android:weightSum="4" >
<Button
android:id="#+id/btnLogin"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight="1"
android:background="#drawable/curvedplanebutton_small"
android:text="Login"
android:textColor="#drawable/button_text_color" />
</LinearLayout>
It is not your fault, default background of Spinner has this kind of image (transparent padding around it). You can see yourself by setting android:background="#ffffff" on Spinner, doing this will remove padding from Spinner's sides and your problem will solve but you will loose Spinner arrow. I suggest you to create your own drawable for Spinner (because you are changing backgrounds of other View) otherwise default background is different for different OS versions and your implementation will seem broke.
Also you are using so many LinerLayouts for this simple layout. Consider this:
<?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="#000000"
android:orientation="vertical"
android:weightSum="100" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="30"
android:paddingBottom="10dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="70"
android:orientation="vertical"
android:padding="16dp" >
<EditText
android:id="#+id/txtMobileNo"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="4dp"
android:background="#ffffff"
android:gravity="center_vertical"
android:hint="MobileNo"
android:padding="4dp"
android:singleLine="true" />
<EditText
android:id="#+id/txtPinNo"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginBottom="4dp"
android:background="#ffffff"
android:gravity="center_vertical"
android:hint="Pin no"
android:inputType="textPassword"
android:padding="4dp"
android:singleLine="true" />
<Spinner
android:id="#+id/lgnspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:background="#ffffff" />
<Button
android:id="#+id/btnLogin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Login" />
</LinearLayout>
</LinearLayout>
Adjust your references again, in case you copy paste my code.
Actually you did code right. It just seem like its not same size with EditText box because you used default background in spinner.
If you changed its background color or image like
android:background="#android:color/darker_gray"
And you can change its background image
android:background="#drawable/spinnerDropDownBackground"
And make sure image is 9 path So that it will not starched in big screen
How to create 9 patch for spinner ?
you will find that you did code right.
And if you want to use default background you have to change your code
android:layout_marginRight="40dp"
android:layout_marginLeft="40dp"
Hope this will help
I need to make a layout which is specific to webpage and it needs to look like a web article with an image and a text left to and under it. Look at the image.
As this is an easy thing to do in a web world, I am not sure how to do it in XML layout.
Obviously, the TextView must be on the left while the image is present, and after it reaches the bottom of the image, it has to stretch to the screen width. I tried this with two TextViews (one for left and another for bottom), but it just does not look right due to the text font size.
EDIT
I also tried to dinamically catch the height of image and then assign it to my TextView, and then make another TextView with the size of the screen under these two elements. This does not work as well as I cannot control the text that is not visible due to limited height of the first TextView.
If you haven't found the answer yet. Here is the same kind of question that is being answered.
How to align TextView around an ImageView?
The only thing what you might have to change in your case is to, make the alignment to be opposite way.
<?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="wrap_content"
android:padding="5dp">
<TextView
android:textSize="18.0sp"
android:id="#+id/message_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text" />
<ImageView
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/message_view"
android:id="#+id/icon" />
Taken from here,
http://dev.androidteam.ru/snippets/textview/leadingmarginspan2
check out this. it does same as you want
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="fill_parent"
android:background="#FFFFFF"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_marginTop="5dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFFFF" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
use this way layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="21dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/imageView1"
android:layout_marginLeft="30dp"
android:textColor="#fff"
android:text="TextView" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:text="TextViewaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:layout_alignBottom="#+id/textView1"></TextView>
</RelativeLayout>
And add in code
TextView tv1=(TextView)findViewById(R.id.textView1);
tv1.setMaxHeight(maxHeight);
where maxHeight is dynamically get height of imageview
and than put condition to by getting height of textview1 to assign text to second textview
may it helps u
like this am I right?
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