How to fix this text input in relative layout - android

I have XML like this :
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/button1" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/button1"
android:layout_toLeftOf="#+id/button1"
android:ems="10"
android:inputType="textMultiLine" />
</RelativeLayout>
And the view like this :
How can I fix that?

The problem is that you are using the android:ems attribute, which sets an exact width to the TextView (measured in EMs).
This overrides android:layout_width="wrap_content", and thus the text in the EditText overflows.
I'm guessing what you actually wanted was to set the size of the text, which should be done using android:textSize and SP units.

Related

Edit text overlaps each other

I am creating an android application in which i am collecting user's some messages.But i am getting some issues such as following..
I have added 3 edit text in alert dialog..the third edit text box having multi line textbox so whenever i am adding multiple lines its getting overlapped to above two edit text
here is the snapshot of the error
Here Is Layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ScrollView
android:layout_width="245dp"
android:layout_height="245dp"
android:layout_weight="0.40"
android:layout_gravity="center_horizontal">
<RelativeLayout
android:layout_width="245dp"
android:layout_height="200dp">
<EditText
android:layout_width="235dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText6"
android:layout_gravity="center_horizontal"
android:hint="Your Email Id"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="240dp"
android:layout_height="wrap_content"
android:id="#+id/editText4"
android:layout_gravity="center_horizontal"
android:hint="Title"
android:singleLine="true"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="236dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText5"
android:hint="Description"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" /></RelativeLayout></ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="#+id/button10"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Reason for your issue is android:inputType="textMultiLine" pushes content when there is a new line!
You can use android:maxLines="1" for your EditText [any way this will be useful for you since you have used android:singleLine="true" with is kind of dipricated ]
Ps: Hard coding android:maxLength will not solve your issue since screens can be in different sizes which makes you hard to decide how many lines you keep!
Also you can use android:maxHeight="xdp" for the editText view, then the limit won't exeed!
You should use
android:maxLength="4"
row numbers you want to fix for your edit text
Use LinearLayout with vertical orientation instead of RelativeLayout.
If u want to use RelativeLayout, then set layout_below attribute of RelativeLayout.
You need to set android:maxLines="4". Set your max lines to solve this issue.
<EditText
android:id="#+id/editText4"
android:maxLines="4"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:hint="Title"
android:layout_alignParentStart="true" />
You can use android:layout_below and android:layout_marginTop in your EditText views and keep distance between your views.
Example :
<EditText
android:layout_width="236dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editText5"
android:hint="Description"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText4"
android:layout_marginTop="20dp"/>

How to put gap between Text and ImageView in EditText in android?

I am using the EditText with drawableLeft property and set ImageView in Right side for ClearText. My Question is how to put gap between text and Imageview in EditText?
Please help me.
Actually I have Like this,My Screenshot is,
Actually I want to Like this,
Create Gap Between Text and ImageView. How it is Possible?.
My xml file is,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/edtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="5dip"
android:drawableLeft="#drawable/search"
android:drawablePadding="10dip"
android:hint="Find"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true" >
</EditText>
<ImageView
android:id="#+id/imgSearchClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/edtSearch"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:contentDescription="#string/app_name"
android:src="#drawable/clear" />
</RelativeLayout>
Okay i got your Question now...you have to use Search view instead of edittext
Here is link:- Check it out
Only this is a solution of your problem
i am using LinearLayout for this
<LinearLayout
android:id="#+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/chatText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine"
android:padding="8dp" />
<ImageView
android:id="#+id/buttonSend"
android:layout_width="50sp"
android:layout_height="50sp"
android:padding="5dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Had the same problem a while ago fixed it with drawablePadding
Hello
Use Linear layout with weight instead of Relative as m showing below:-
<LinearLayout
width
hight
orientation="horizontal">
<EditText
android:id="#+id/edtSearch"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:drawableLeft="#drawable/search"
android:drawablePadding="10dip"
android:hint="Find"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true" >
</EditText>
<ImageView
android:id="#+id/imgSearchClear"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:contentDescription="#string/app_name"
android:src="#drawable/clear" />
</LinearLayout>
if you found any issue regarding this please let me know..i love to help you
or in relative layou you can use drawable padding
Spartacus thanks :)
I can try to implement your code but It Like this,
and I want to Like this,
Set the right padding of EditText to the width of Clear button. Set all the dimension in dimen folder so that it will be compatible with all device sizes.

How to set the max textsize in android?

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/lbd_user_pt_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/lbd_user_pt"
android:paddingRight="10dp"
android:text="#string/leader_board_my_pt"/>
<TextView
android:id="#+id/lbd_user_pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:text="90000"
android:textDirection="ltr" />
</RelativeLayout>
Currently I have a relative layout that is the horizonal line. And there is two textview inside . Since the length of the relative layout is too small, the 2 textview overlay or behave werid
like:
[user_pt_tag user_pt]
The problem is , I would like the user pt align right and expand to left , also , the common textsize is 20sp , if the pt overlap the tag , the size will be reduce. (the pt textview is at most 5 digits , that will no more digit than that) How to achieve that? Thanks
//try to use Linear Layout rather than Relative Layout like below
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="#+id/lbd_user_pt_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:text="#string/leader_board_my_pt"/>
<TextView
android:id="#+id/lbd_user_pt"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="right"
android:text="90000"
android:textDirection="ltr" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/lbd_user_pt_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:maxLength="5"//you can give the length as per your need
android:layout_toLeftOf="#+id/lbd_user_pt"
android:paddingRight="10dp"
android:text="leader_board_my_pt"/>
<TextView
android:id="#+id/lbd_user_pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:text="90000"
android:textDirection="ltr" />
</RelativeLayout>

How can I make EditText control take more free space?

In the following UI, I hope the two buttons both btnAddress and btnDelete take minimum space,
and editnumber take max space, how can I do? Need I use RelativeLayout layout? Thanks!
BTW, the following code, the btnDelete button only display a part.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="left"
android:orientation="horizontal" >
<EditText
android:id="#+id/editnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:phoneNumber="true"
android:ems="10" >
</EditText>
<Button
android:id="#+id/btnAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/BtnAddressMin" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/BtnDeleteMin" />
</LinearLayout>
This should do it. Giving editnumber a weight of 1. Leve the rest as it is.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="left"
android:orientation="horizontal" >
<EditText
android:id="#+id/editnumber"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:phoneNumber="true"
android:ems="10" >
</EditText>
<Button
android:id="#+id/btnAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/BtnAddressMin" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/BtnDeleteMin" />
</LinearLayout>
Instead of fixing the length of EditText with ems, use layout_weight to fill the remaining space.
<EditText
android:id="#+id/editnumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:phoneNumber="true" />
Edit: I'm not sure if android:phoneNumber="true" is still recommended or not, but I would change it to android:inputType="phone" instead.
Give the android:layout_weight="1 to edit text .No need to change it to relative layout
<EditText
android:id="#+id/editnumber"
android:layout_width="0dp"//no need to specifing the width if parent layout is horizontal
android:layout_height="wrap_content"
android:phoneNumber="true"
android:layout_weight="1";>
</EditText>
Doing this Edittext will take maximum space and remaing space will be left for other View.Other then this no need to change anything in your xml

Android Xml button layout

I have a problem while placing the buttons in my xml file.
Now what I want is that the "ok" button at the bottom should come below the mileage edit text that is at the second last strip. I am using a scroll view before the button. Also I am using a single image as a background.
How is it possible that all my buttons in my application only come on the second last strip (gray color)? The rest of the layout should come in between (i.e. between top gray strip and the bottom gray strip).
I tried using margin_top or margin_bottom in 'dp' but its not coming properly plus on every other phone the layout of button changes. Here is my code (.xml file):
<?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="#drawable/menu"
android:padding="10dp">
<ScrollView
android:id="#+id/scv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="105dp"
android:layout_marginBottom="105dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Year"
android:inputType="date" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_alignRight="#+id/editText1"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_alignRight="#+id/spinner1"
android:layout_below="#+id/spinner1"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner2"
android:layout_alignRight="#+id/spinner2"
android:layout_below="#+id/spinner2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner3"
android:layout_below="#+id/spinner3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Mileage"
android:inputType="number" />
</RelativeLayout>
</ScrollView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:text="OK" />
</RelativeLayout>
You should never use a single image for your complete layout on Android. That just doesn't run very well as you have so many different screen sizes.
I'd recommend you cut the graphic out in portions and make it stretch so it will fit depending on the screen size. It's not really possible to help you much more based on the poorly copy paste of your own code and the lack of visualization of what you want the graphic to look like.
For your button xml, try
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/scv"
android:layout_centerHorizontal="true"
android:text="OK" />
You can add android:layout_marginTop="5sp" changing the value if necessary.
This will place your button below your scrollview.

Categories

Resources