How can I change the height of a EditText and a Button? - android

I have this EditText and Button, and I have to reduce its height. I try with android:height="10px" but it doesn't work. Btw android:width="180px" works OK, then I don't know why I can't adjust the height.
Here is the code:
<EditText
android:id="#+id/Movile"
android:layout_alignBaseline="#+id/MovileLabel"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="180px"
android:height="10px"/>
<Button
android:id="#+id/inviteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/invite"
android:width="100px"
android:height="5px"
android:layout_marginLeft="40dip"/>

Instead of setting values to android:height="10px" use android:layout_height="10px"
android:layout_width="180px"
android:layout_height="10px"

use android:minHeight="120dp" attribute.
if need to increase height dynamically add
android:layout_height="wrap_content"

You need to get rid of the "wrap_content" properties and just have the fixed width and height as so:
<EditText
android:id="#+id/Movile"
android:layout_alignBaseline="#+id/MovileLabel"
android:layout_alignParentRight="true"
android:layout_width="180px"
android:layout_height="10px"/>
<Button
android:id="#+id/inviteButton"
android:text="#string/invite"
android:layout_width="100px"
android:layout_height="5px"
android:layout_marginLeft="40dip"/>

You can't decrase size of TextEdit if the font is too big inside.
try android:textSize='6sp'

Related

How to make a fix size of edit field android

I am working on android application in which i want to fix the size of the box of editfield. For example if i want to add 100 words on it, then it will not increase the size of the edit field. Characters should remains inside the box without increasing the size of edit text. I have paste the xml code of my editText along with the images.
<EditText
android:id="#+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:background="#color/Beige"
android:enabled="false"
android:lines="1"
android:ems="15"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="#color/Black"
android:textSize="12sp" />
Thanks in advance
Fix your field's width.
You can do this in several ways:
LinearLayout with weights. Your container should have android:weightSum="100" (instead of 100 you can place your number). For example you can go here or here. Using weights you should set android:layout_width="0dp" in order to see result.
RelativeLayout with margins. Set first EditText to android:layout_alignParentRight="true" and android:layout_toRightOf="IdOfTextView". Set right margin to (e.g.) 10dp. EditField will be stretched in order to fill all free space.
You can set android:maxWidth to some value in dp or px. Or maxLength or maxEms can do the trick.
Change:
android:layout_width="wrap_content"
To Something like
android:layout_width="200dp"
or whatever size you choose.
If your are intending to set the height using the layout_weight property set your
layout_height="0"
otherwise set
layout_height="100dp"
or whatever you want your fixed height to be.
Maybe you need to use the XML android:maxLines and android:lines attribute and manipulate the maxLength.
<EditText
android:id="#+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:background="#color/Beige"
android:enabled="false"
android:lines="5"
android:ems="15"
android:maxLines="100"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="#color/Black"
android:textSize="12sp" />
Source: Android Developers Max Lines.

Android Edittext width automatically changed when input large text

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.

My Edittext getting extended while typing the text

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

How to use android:maxWidth?

I want to set a maximum width of an edit box. So I created this small layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxWidth="150dp" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
But it doesn't work, the box could be more than 150 dp anyway. android:maxWidth="150dp" in the EditText will give the same result. I have read ( maxWidth doesn't work with fill_parent ) that setting both max- and min width to the same size should solve it:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:maxWidth="50dp"
android:minWidth="50dp" />
But it doesn't.
I have found a solution to my problem here here:
Setting a maximum width on a ViewGroup
And this works great. But I guess the maxWidth attribute is here for I reason. How should it be used? Or is there any documentation on this? I have spend hours on this problem, and still doesn't understand how to use this simple attribute.
I want to set a maximum width of an edit box.
In your example:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" />
The layout_width and ems attributes are trying to set the same value. Android seems to choose the larger fill_parent value and ignores the other. And when you use this:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:maxWidth="50dp"
android:minWidth="50dp" />
Here ems and maxWidth are trying to set the same value, again the greater value is used. So depending on what you actually want you can use:
<EditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
or replace android:ems="10" with android:maxWidth="50dp" if you prefer to work with dp.
Lastly your LinearLayout only has one child, the EditText. Typically when this happens you can remove the LinearLayout tags and use the EditText by itself.
To those who are seeing this question in recent years, we have app:layout_constraintWidth_max="225dp" now. Put your layout inside contsraint layout and use this on the view you want to have max width.

Android Text is wrapped in button - why?

I have the following XML:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/verylongtext" android:layout_weight="1000" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sometext" android:onClick="onClickButton" android:layout_weight="1" />
</LinearLayout>
Though I have set a layout_weight there is still a linebreak in the text on the button, the button should show
sometext
but it shows
somet
ext
Why is this and how can I fix it?
Thanks!
Include android:singleLine="true" to Button xml.
You don't specify the orientation of your LinearLayout, so it is defaulting to horizontal. The TextView is squeezing the Button. Also, when you use android:layout_weight, then you often don't want to constrain the objects in the layout in the relevant dimension, so you can put "0px" instead of "wrap_content" or "match_parent" and let the weight determine the respective proportional sizes.

Categories

Resources