2011-10-26 37 views
7

Vì vậy, tôi có văn bản này "Tới", một văn bản để nhập liên hệ và nút tìm kiếm để tìm kiếm liên hệ tất cả trong một dòng. Các textview và nút là tất cả ở nơi tốt nhưng vấn đề là edittext là nhỏ, tôi muốn nó chiếm tất cả các không gian còn lại. Dưới đây là các mã:EditText sẽ không lấp đầy không gian còn lại

<RelativeLayout 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:paddingTop="10dp"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="To: " 
      android:textColor="#000000" 
      android:paddingTop="10dp" 
      android:layout_toLeftOf="@+id/editText_recipient" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="10dp"/> 
     <EditText 
      android:id="@+id/editText_recipient" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:hint="Enter Number" 
      android:inputType="number" 
      android:textSize="12sp" 
      android:layout_toLeftOf="@+id/button_recipient_picker" 
      android:layout_marginLeft="5dp"/> 
     <Button 
      android:id="@+id/button_recipient_picker" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Browse .." 
      android:layout_alignParentRight="true" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:onClick="doLaunchContactPicker"/> 
     </RelativeLayout> 
+0

Trả lời bằng RelativeLayout bên dưới – Br0thazS0ul

Trả lời

17
<LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:paddingTop="10dp"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="To: " 
      android:textColor="#000000" 
      android:paddingTop="10dp" 
      android:layout_marginLeft="10dp"/> 
     <EditText 
      android:id="@+id/editText_recipient" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:hint="Enter Number" 
      android:inputType="number" 
      android:textSize="12sp" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
     /> 
     <Button 
      android:id="@+id/button_recipient_picker" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Browse .." 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:onClick="doLaunchContactPicker"/> 
     </LinearLayout> 

sử dụng bố trí này, tôi chuyển đổi bố trí của bạn để tuyến tính (mặc định nằm ngang). và thêm layout_weight vào editText, nó sẽ chiếm không gian còn lại.

+0

Cảm ơn bạn: D Nó hoạt động tốt :) – kev

2

Đối với những người cần câu trả lời cho điều này và để giải quyết bài đăng này mà không đưa ra giải pháp thay thế, câu trả lời khá đơn giản. Bạn cần phải thông báo cho mọi điều khiển vị trí theo nhau và áp dụng cho điều khiển cần có không gian sẵn có android:layout_width = "match_parent" mặc dù trong LinearLayout, điều này sẽ đẩy mọi điều khiển khác liên kết ra khỏi màn hình, trong RelativeLayout nó hoạt động hoàn hảo

<RelativeLayout 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:paddingTop="10dp"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="To: " 
     android:textColor="#000000" 
     android:paddingTop="10dp" 
     android:layout_toLeftOf="@+id/editText_recipient" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="10dp"/> 
    <EditText 
     android:id="@+id/editText_recipient" 
     android:layout_height="wrap_content" 
     android:layout_width="MATCH_PARENT" 
     android:hint="Enter number" 
     android:inputType="number" 
     android:textSize="12sp" 
     android:layout_toLeftOf="@+id/button_recipient_picker" 
     android:layout_marginLeft="5dp"/> 
    <Button 
     android:id="@+id/button_recipient_picker" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:text="Browse .." 
     android:layout_alignParentRight="true" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:onClick="doLaunchContactPicker"/> 
    </RelativeLayout> 
Các vấn đề liên quan