开发者

Placing two view in one row using RelativeLayout

I want the EditText to fill all the available space to the right side until the button placed on the right of it. I'm using RelativeLayout to construct such a view. But in result I don't have my button visible, the only EditText. Please advice how to make both of them visible.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_h开发者_如何学运维eight="fill_parent">

  <RelativeLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:padding="10dp">

  <EditText
   android:id="@+id/edit_text"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:hint="Task description">
  </EditText>

 <Button
   android:id="@+id/ok_button"
   android:layout_width="wrap_content"   
   android:layout_height="wrap_content"
   android:text="OK"
   android:layout_toRightOf="@id/edit_text">
  </Button>     
  </RelativeLayout>

</LinearLayout>


You're putting your button first. You have to place the item you want fixed before the others.

 <Button
   android:id="@+id/ok_button"
   android:layout_width="wrap_content"   
   android:layout_height="wrap_content"
   android:text="OK"
   android:layout_alignParentRight="true"
    />

  <EditText
   android:id="@+id/edit_text"
   android:layout="align_parent_left"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_toLeftOf="@id/ok_button"
   android:hint="Task description"
/>

The way you have it, your edittext knows nothing about the button that follows it, so why should it not take up the entire width of the parent just like you told it to?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜