2014-10-04 24 views
0

我在EditText中有一個嵌套的按鈕。我使用RelativeLayout來做到這一點。問題是文本輸入與按鈕重疊。我怎樣才能防止這種情況發生?也許是一種限制每行字符的方法。我曾嘗試設置android:maxLength,但它應用於整個EditText而不是每行。防止輸入的文本重疊在嵌套的按鈕裏面EditText

enter image description here

<RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/linearLayout" 
      > 
      <EditText 
       android:id="@+id/item" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/rounded_edit" 
       android:ems="10" 
       android:hint="samplehint" 
       android:lines="5" 
       android:maxLines="5" 
       android:minLines="1" 
       android:padding="10dp" 
       android:paddingRight="50dp" 
       android:inputType="textMultiLine" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentTop="true" /> 
      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Done" 
       android:layout_centerVertical="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" /> 

      </RelativeLayout> 

回答

4

您需要使用LinearLayout而不是RelativeLayout。事情是這樣的:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:padding="5dp" 
     android:gravity="center|start" 
     android:text="Samplesamplesamplesamplesamplesamplesamplesamplesamplesamplesamplesample" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent"/> 

    <Button 
     android:text="Button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

</LinearLayout> 

應該是這樣的:

enter image description here

0

我加入android:drawablePadding="35dip"到EditText上解決了這個問題。但是因爲沒有drawable就無法工作,所以我在按鈕的方向上添加了一個空的drawable。

android:drawablePadding="35dip 
android:drawableRight="@android:color/transparent"