I have an EditText which I want to fill all the horizontal width available but the width should not be greater than 200dp
This makes EditText adapt to any screen size and still makes it look good on large screens (stretching horizontally won't look nice on a large screen).
How to do this in Android?
I saw that maxWidth=200dp
and layoutWidth=fill_parent
do not work together:
<EditText android:id="@+id/oldpassword"
android:hint="@string/youroldpassword"
android:inputType="textpassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxWidth="250dp" />
If maxWidth
and layoutWidth=fill_parent
do not work together, then what is the maxWidth
meant for?
In other words, if the EditBox does not change its width dynamically, then what would you need maxWidth
for?
you can set width programmatically depending on the device screen size. like
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
EditText et = (EditText)findViewById(R.id.editText);
if(width > 200)
{
et.setWidth(200);
}
else
{
et.setWidth(width);
}
i have solution,
look if you set android:layout_width="fill_parent"
it was always having it's width which have parent but when you set android:layout_width="wrap_content"
then it was increase size width with content while you entering Text in EditText, now if you use android:maxWidth="250dp"
with android:layout_width="wrap_content"
then it will increase it's width upto 250dp while entering value in EditText
use
<EditText android:id="@+id/oldpassword"
android:hint="@string/youroldpassword"
android:inputType="textpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="250dp" />`
or use
<EditText android:id="@+id/oldpassword"
android:hint="@string/youroldpassword"
android:inputType="textpassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With