Reputation: 17206
I am trying to have an EditText
widget next to a Button
, also with a TextView
underneath. The EditText
should resize and fill the screen accordingly, while the Button's width should always be only what it needs to be (I did this by setting the width to wrap_content
).
The layout I am trying to accomplish should not be relative. Below is the code I have so far (some of which was found here on StackOverflow). Removing the TextView gives the desired appearance for the EditText and Button, but when the TextView is added, the view goes pretty awry.
Any insight would help!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent"
>
<EditText android:text="@+id/EditText01"
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="fill_parent"
/>
<Button android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
Upvotes: 2
Views: 11567
Reputation: 48559
Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_width="fill_parent">
<Button
android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
</Button>
<EditText android:text="@+id/EditText01"
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/Button01"
android:layout_width="fill_parent">
</EditText>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/EditText01"
android:text="@string/hello"
/>
</RelativeLayout>
Upvotes: 10