what is ems and why the editfield size is same (width)?
what is ems and why the editfield size is same (width)?
I just started android development, so I have two question in my mind
First, why the size of edit field does not change its width.
width
Secondly, what is the meaning of these two lines
android:layout_weight="1.0"
android:layout_weight="1.0"
android:ems="50"
android:ems="50"
When I used in layout form android:layout_weight= it take value as 0.1, why ?
android:layout_weight=
0.1
On field it take 1.0, why ?
what is ems ?
1.0
ems
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/login_header"
android:gravity="center_horizontal"
android:textSize="30dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/username"
android:textSize="18dp"/>
<EditText
android:id="@+id/username"
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:ems="50"
android:inputType="text"/ >
</LinearLayout>
<Button
android:id="@+id/login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/login_header"
android:layout_margin="10dp"/>
</LinearLayout>
stackoverflow.com/questions/7053738/…
– Karan Mer
Sep 17 '13 at 16:33
1 Answer
1
Your EditText Width is not changing because you give the layout_weight = 1 to the EditText that means the EditText will take the full remaining width of your Horizontal LinearLayout in which it drawn.
if you will use the .5 layout_weight in TextView and EditText . Both of them will take the half half portion of whole width. Its a horizontal LinearLayout so weight will affect the width of views. So the width of Edittext is unuseful. and in case of Vertcal LinearLayout the height of the View will be affected with layout_weight.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/username"
android:textSize="18dp"
android:layout_weight=".5" />
<EditText
android:id="@+id/username"
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:ems="50"
android:inputType="text" >
</EditText>
</LinearLayout>
Ems:- is a typographical term. For more about ems check this.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
en.wikipedia.org/wiki/Em_%28typography%29
– FoamyGuy
Sep 17 '13 at 16:25