2011-01-29 146 views
0

我需要Button保持在右侧,然后EditText框自动占用剩余的空间(重新调整大小)。Android - 自动调整大小

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent">  
      <EditText android:id="@+id/PPL_Txt" 
       android:layout_height="fill_parent" 
       android:inputType="numberDecimal" 
       android:layout_width="wrap_content" /> 
      <Button android:text="@+id/Button01" 
       android:id="@+id/Button01" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent"> 
      </Button> 
     </LinearLayout> 

任何帮助将不胜感激。

回答

1

尝试设置layout_width =“FILL_PARENT”上的EditText

<EditText android:id="@+id/PPL_Txt" 
       android:layout_height="fill_parent" 
       android:inputType="numberDecimal" 
       android:layout_width="fill_parent" /> 
+0

不起作用,EditText占用所有空间并且按钮消失。 – user576820 2011-01-29 12:23:58

0

试试这个

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
     <EditText android:layout_height="wrap_content" android:id="@+id/editText1" android:text="EditText" android:layout_width="wrap_content" android:layout_alignParentLeft="true"></EditText> 
     <Button android:layout_height="wrap_content" android:text="Button" android:layout_width="wrap_content" android:id="@+id/button1" android:layout_alignParentTop="true"></Button> 
    </LinearLayout> 
0

用于布局重排序它,你必须发挥它到它正确地去比,显然,像在CSS中设置%在Android中不可用。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
       <EditText android:id="@+id/PPL_Txt" 
        android:inputType="numberDecimal" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="30"/> 
       <Button android:layout_width="fill_parent" 
       android:id="@+id/Button01" 
       android:layout_weight="70" 
       android:layout_height="wrap_content" 
       android:text="Options"> 
       </Button> 
     </LinearLayout> 
0

排序的沿user576820的线:设置的EditText到0dp和layout_weight的为1。layout_width离开按钮的layout_width为wrap_content和没有设置layout_weight(或将其设置为0)。这样,你不必猜测重量比。