When the EditText not gets the focus, the hint content is not in the middle. Why is this happening? Who can help me?
Less than 7.0 its ok
in the 7.1 8.0 it unable to display normally
this is my xml code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="90px">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:layout_marginLeft="30px"
android:background="#color/c_dbdbdb"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30px"
android:text="年龄"
android:textColor="#color/c_666666"
android:textSize="32px"/>
<EditText
android:id="#+id/et_new_appointment_age"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="230px"
android:background="#null"
android:gravity="center_vertical"
android:hint="请输入年龄"
android:inputType="number"
android:minWidth="200px"
android:textColor="#color/c_333333"
android:textColorHint="#color/c_999999"
android:textSize="32px"/>
</RelativeLayout>
Define your edit text ellipsize as start and try I think it will help you.
android:ellipsize="start"
put editText with width and height as wrap content and use
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
inside edit text. it will work.
Related
I'm trying to get the bottom of my TextView and EditText to line up (perhaps not to the pixel, but close) inside of a RelativeLayout. But layout_alignBottom seems to line up their center line instead of their bottom:
I tried layout_alignBaseline also, but the result was that the EditText does not display on the screen. I also made various efforts at adjusting padding, but it didn't change anything. This seems like it should be easy and a common issue, but I couldn't find anything Googling. Any help would be greatly appreciated.
Thanks.
<TextView
android:id="#+id/firstNameLabel"
android:layout_marginTop="20dp"
android:layout_marginRight="24dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name" />
<EditText
android:layout_toRightOf="#+id/firstNameLabel"
android:layout_alignBottom="#+id/firstNameLabel"
android:id="#+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
Try this.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/firstNameLabel"
android:layout_marginRight="24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="First Name"
android:textSize="20sp"/>
<EditText
android:layout_toRightOf="#+id/firstNameLabel"
android:layout_alignParentBottom="true"
android:id="#+id/firstName"
android:hint="YO BABY"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Hope this helps.
Remove margin top from code and check
What's causing this is the EditText being bigger than the textview. Check your layout that contains both and set the gravity to "center" or "center_vertical".
Edit: If you're using RelativeLayout, you should probably use "layout_centerVertical" or "layout_centerInParent" instead
i have edittext and when i input some text width automatically Increased. this is a my edit text xml code
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="#+id/namefild"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/edittextbackground"
android:hint="Name"
android:paddingLeft="15dp"
android:textColorHint="#e2e0e0" />
</RelativeLayout>
how i can solve my problem? i don't need to change edittext 's width .if anyone knows solution please help me
try this property android:layout_width="0dp"
its because the width of EditText is wrap_content. Try using fixed width or match_parent. It should work.
I have a EditText look like this in my layout xml and it's not expanding when the user hit enter
<EditText
android:layout_height="40dp"
android:layout_width="fill_parent"
android:gravity="top"
android:maxLines="10"
android:minHeight="40dp"
android:id="#+id/edSearch"
android:layout_toLeftOf="#+id/btnSearch"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:hint="City..."
/>
but when i changed android:layout_height="40dp" to android:layout_height="wrap_content" the the edittext is able to expand as the user hit enter.
how I can keep my EditText expanding while keeping this line android:layout_height="40dp"
Thanks
Try this
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="Top"
android:maxLines="10"
android:minHeight="40dp"
android:id="#+id/edSearch"
android:layout_toLeftOf="#+id/btnSearch"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:inputType="textMultiLine"
android:hint="City..."
/>
Hope this will work
I'm using following code and it's working great. to set minimum height instead of setting layout_height to 40dp set it wrap_content and set attribute of minLines to achieve this as show below in code example
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:minLines="4"
android:maxLines="10"
/>
Set property android:multiline="true".
hope this will help you.
Set android:multiline="true" along with android:gravity="left|top"
My Edittext its getting extend automatically while typing the text,Dont know what mistake i have done, please check my screen shot for exactly what my issue is, help me to find a solution. Thanks in advance.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<EditText
android:id="#+id/oldpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectdate"
android:ems="10"
android:hint="#string/oldpass"
android:inputType="textPassword"
android:paddingLeft="5dip" >
</EditText>
</LinearLayout>
</LinearLayout>
check my screen shot for how its extend while typing
your height and weight are Wrap_content as it adjust upon the length of the text you given
change that to fixed dp length
android:layout_width="150dp"
android:layout_height="wrap_content"
It is due to this layout definition: android:layout_width="wrap_content"
You're basically telling that your EditText should fit the content. That means it will have a default size, but once you're typing in it and making it wider, it will extend according to the text it has inside.
You probably want to use android:layout_width="match_parent" to fit it to the screen, or play around with android:layout_weight to make it proportional to other layout items.
Set WEIGHT property of your edittext it will not extended.
android:layout_width="0dp"
android:layout_weight="1"
Try this
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center" >
<EditText
android:id="#+id/oldpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectdate"
android:ems="10"
android:hint="#string/oldpass"
android:inputType="textPassword"
android:paddingLeft="5dip" >
</EditText>
</LinearLayout>
I believe your issue is you are setting the layout_width of the EditText as wrap_content
I have a Button with its width as match_parent. And I want a image/icon with a text in its center. I have triedandroid:drawableStart attribute but its of no help. I don't know what I am missing. Is there any one who is also facing the same problem.
Note:This link is not solving my problem. I am attaching my button portion of xml
<Button
android:background="#drawable/blue_button"
android:id="#+id/btn_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:drawableStart="#drawable/ic_list"
android:text="#string/btn_schedule"
android:textColor="#android:color/white" />
After adding these attribute my text is coming on center but image/icon is still on left side of button. Can any body help!!!
You might want to check my answer to this question:
Android Button with text and image
Its an ugly solution but it you want the image and text to be centered as a group in the button rather than text center and drawable padded from the side then its the only way I have found.
100% working
<FrameLayout
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:clickable="false"
android:drawableLeft="#android:drawable/ic_delete"
android:focusable="false"
android:gravity="center"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="Button Challenge" />
from here
This works for me. Basically play with the paddingLeft and PaddingRight of the button to get the text and image close together to the center.
Note: Might be an issue with rather long texts.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="search button"
android:drawableStart="#drawable/ic_action_search"
android:paddingLeft="60dp"
android:paddingRight="60dp"/>
</LinearLayout>
I had the same problem and I hadn't found anywhere clear solution. BUT I got some information which also help me to provide following solutions (I have chosen the second one):
Create image which will contain your image and text
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/YOUR_IMAGE"
android:gravity="center_horizontal|center_vertical" />
It is not so clear and you have to add more complicated changes to your layout but it is easier to modify the text later
<FrameLayout
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_height="50dp"
android:layout_width="match_parent" />
<TextView
android:text="sample"
android:layout_height="50dp"
android:layout_width="wrap_content"
android:drawableLeft="#drawable/YOUR_IMAGE"
android:gravity="center_horizontal|center_vertical" />
</FrameLayout>
I tried android:drawableTop
The image shown in the center of the button