2015-10-12 15 views
0

正如你在圖片中看到的是兩個按鈕右邊的重新排列的空間,我希望中間的搜索欄只要它能夠延伸,所以沒有可用空間,我應該讓這兩個按鈕向右移動,並以這種方式爲搜索欄提供更多空間來擴展,如果是這樣,我該怎麼做?使編輯文字適合可用空間Android

enter image description here

佈局

<LinearLayout android:id="@+id/findControls" android:layout_width="match_parent" 
     android:layout_alignParentTop="true" 
     android:layout_height="wrap_content" android:paddingTop="5dip" 
     android:paddingLeft="4dip" android:paddingRight="4dip" 
     android:paddingBottom="1dip" android:background="@drawable/topbar"> 

     <ImageButton android:src="@drawable/ic_btn_find_prev" 
      android:id="@+id/find_previous" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <ImageButton android:src="@drawable/ic_btn_find_next" 
      android:id="@+id/find_next" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:clickable="true" /> 

     <LinearLayout android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:orientation="vertical" android:layout_marginRight="6dip"> 

      <EditText android:id="@+id/find_value" android:layout_width="133dp" 
       android:layout_height="wrap_content" android:scrollHorizontally="true" 
       android:singleLine="true" android:ellipsize="end" 
       android:inputType="text" android:hint="@string/SearchDialog.Hint" /> 

     </LinearLayout> 
+0

發佈您正在使用的佈局。 – Simas

回答

1

試試這個:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1" 
    android:background="@color/cardview_light_background"> 

    <ImageButton 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_margin="2dp" 
     android:background="@color/cardview_dark_background"/> 

    <ImageButton 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_margin="2dp" 
     android:background="@color/cardview_dark_background"/> 

    <EditText 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_margin="2dp" 
     android:layout_height="match_parent"/> 

    <ImageButton 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_margin="2dp" 
     android:background="@color/cardview_dark_background"/> 

    <ImageButton 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_margin="2dp" 
     android:background="@color/cardview_dark_background"/> 
</LinearLayout> 
+0

非常感謝您親切的先生 – AlanRubinoff

0

嘗試使用match_parentlayout_width。和definitly不固定133dp。

所以從wrap_contentmatch_parentLinearLayout變化,並添加match_parentEditText

<LinearLayout android:layout_height="wrap_content" 
        android:orientation="vertical" android:layout_marginRight="6dip" 
        android:layout_width="match_parent"> 

    <EditText android:id="@+id/find_value" android:layout_width="match_parent" 
        android:layout_height="wrap_content" android:scrollHorizontally="true" 
        android:singleLine="true" android:ellipsize="end" 
        android:inputType="text" android:hint="@string/SearchDialog.Hint" /> 
</LinearLayout> 
0

你可以使用一個RelativeLayout的代替:

<RelativeLayout android:id="@+id/findControls" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:paddingBottom="1dip" 
      android:paddingLeft="4dip" 
      android:paddingRight="4dip" 
      android:paddingTop="5dip"> 

<ImageButton 
    android:id="@+id/find_previous" 
    android:layout_alignParentLeft="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add"/> 

<ImageButton 
    android:id="@+id/find_next" 
    android:layout_toRightOf="@id/find_previous" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:src="@drawable/ic_add"/> 


<EditText 
     android:id="@+id/find_value" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:ellipsize="end" 
     android:hint="" 
     android:layout_toRightOf="@id/find_next" 
     android:layout_toLeftOf="@id/find_next2" 
     android:inputType="text" 
     android:scrollHorizontally="true" 
     android:singleLine="true"/> 


<ImageButton 
    android:id="@+id/find_previous2" 
    android:layout_alignParentRight="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add"/> 

<ImageButton 
    android:id="@+id/find_next2" 
    android:layout_toLeftOf="@id/find_previous2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:src="@drawable/ic_add"/> 

對準你的按鈕給父母留下/對。使用toLeftOf和toRightOf設置您的EditText。