How to make EditText smaller than default?

I need to show a large number of EditText controls on the screen, each of which will allow you to enter only 0-2 digits. The default size of the EditText is too wide for me to display enough EditText controls on the screen, but I could not figure out how to make them narrower. I tried the following attributes in

XML:

android:maxLength="2" android:layout_width="20dip" android:maxWidth="20px" android:ems="2" android:maxEms="2" 

So the question is how to make EditText smaller than the default?

+6
android android-layout android-xml
source share
4 answers

Try to show the difference instead. Use layout_width with the specified width.

 <?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" > <EditText android:width="10dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="40dip" android:layout_height="wrap_content" android:text="@string/hello" android:maxLength="2" /> </LinearLayout> 

alt text http://i40.tinypic.com/2953fao.jpg

+9
source share

Hey, as soon as you try this, it may work ....... android: textAppearance = "android: atr / textAppearanceSmall"

+4
source share

In case you get to this page to find how to achieve this in Java code.

 txtSample.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)}); 
+1
source share

When in the table, as you described, android: layout_gravity = "left" will hide EditText to the specified size of EditText

+1
source share

All Articles