开发者

EditText and Button on the same line with TextView underneath?

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" 
              and开发者_如何学Goroid: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>


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜