Sunday, 15 January 2012

android - How to create an EditText of dynamic fixed width -



android - How to create an EditText of dynamic fixed width -

i'm working on app xml looks bit this:

<tablerow android:layout_width="match_parent" android:layout_height="fill_parent"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/receiver_name" android:layout_weight="1" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="3" android:maxlength="30" android:maxlines="1" /> </tablerow>

what want, no matter device have, textview should take 1/4th of width, , edittext should take 3/4ths of width.

as now, code works - until start typing. edittext gets wider , wider type more , more it. how create edittext stays same width assigned layout_weight parameters?

you should utilize linearlayout :

<linearlayout android:layout_width="match_parent" android:layout_height="fill_parent"> <textview android:layout_width="0dp" android:layout_height="wrap_content" android:text="@string/receiver_name" android:layout_weight="1" /> <edittext android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:maxlength="30" android:maxlines="1" /> </linearlayout>

hope can help =)

android xml android-layout android-edittext

No comments:

Post a Comment