2011-10-26 15 views
7

Bu yüzden "To" adlı bir metin görünümünde, kişiyi girmek için bir edittext ve bir satırda kişileri aramak için bir arama düğmesi var. Metin görünümü ve düğmesi iyi bir yerde ama sorun edittext küçük, kalan tüm alanları işgal etmesini istiyorum. İşte kod:EditText, kalan alanı doldurmayacaktır.

<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

Aşağıdaki RelativeLayout ile Yanıtlayın – Br0thazS0ul

cevap

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> 

kullanımı bu düzen, ı (yatay varsayılan) doğrusal için düzeninizi dönüştürülür. ve editText için bir layout_weight ekledik, kalan alanı kaplayacak.

+0

Teşekkür ederim: D Harika çalışıyor :) – kev

2

Buna bir yanıt vermesi gereken ve bu yazıyı bir alternatif vermeden çözmek isteyenler için cevap oldukça basittir. Bir RelativeLayout yılında, birbirini göre konumlandırmak ve hatta LinearLayout yılında, bu ekranın dışına hizalanmış her kontrole itecek olsa kullanılabilir alanı android:layout_width = "match_parent" almalı denetime uygulanacağı yeri her kontrole anlatmak gerekir o mükemmel çalışıyor

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