Reputation: 2255
In the following UI, I hope the two buttons both btnAddress and btnDelete take minimum space, and editnumber take max space, how can I do? Need I use RelativeLayout layout? Thanks!
BTW, the following code, the btnDelete button only display a part.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="left"
android:orientation="horizontal" >
<EditText
android:id="@+id/editnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:phoneNumber="true"
android:ems="10" >
</EditText>
<Button
android:id="@+id/btnAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BtnAddressMin" />
<Button
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BtnDeleteMin" />
</LinearLayout>
Upvotes: 0
Views: 183
Reputation: 6096
Give the android:layout_weight="1
to edit text .No need to change it to relative layout
<EditText
android:id="@+id/editnumber"
android:layout_width="0dp"//no need to specifing the width if parent layout is horizontal
android:layout_height="wrap_content"
android:phoneNumber="true"
android:layout_weight="1";>
</EditText>
Doing this Edittext
will take maximum space and remaing space will be left for other View
.Other then this no need to change anything in your xml
Upvotes: 1
Reputation: 4707
Instead of fixing the length of EditText
with ems
, use layout_weight
to fill the remaining space.
<EditText
android:id="@+id/editnumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:phoneNumber="true" />
Edit: I'm not sure if android:phoneNumber="true"
is still recommended or not, but I would change it to android:inputType="phone"
instead.
Upvotes: 1
Reputation: 14226
This should do it. Giving editnumber a weight of 1. Leve the rest as it is.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="left"
android:orientation="horizontal" >
<EditText
android:id="@+id/editnumber"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:phoneNumber="true"
android:ems="10" >
</EditText>
<Button
android:id="@+id/btnAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BtnAddressMin" />
<Button
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BtnDeleteMin" />
</LinearLayout>
Upvotes: 1