2

ここに私が持っていEditTextますImageButton

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/layout1"
    android:weightSum="1.0">

    <EditText
        android:id="@+id/searchBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/search"
        android:layout_weight=".86"
        android:textStyle="italic|normal"
        android:typeface="normal"
        android:singleLine="true"
        android:ellipsize="end" />

    <ImageButton
        android:layout_height="match_parent"
        android:layout_width="0px"
        android:layout_weight=".14"
        android:background="@drawable/search_button_selector"/>

</LinearLayout>

でテキストを入力し始めない限り、すべて問題ないようですEditText

最初は次のようになります。

ここに画像の説明を入力

そして、テキストを入力した後、私のImageButtonサイズは小さくなります:

ここに画像の説明を入力

EditText静止させる方法は?

4

3 に答える 3

4

EditText の layout_width を変更するandroid:layout_width="0dp"と修正されると思います。これにより、 LinearLayout が幅を制御して、重みによって決定されたスペースを埋めることができます。

于 2012-11-26T19:25:11.097 に答える
2

を使用してRelativeLayout、これらのweight設定を削除します。画像を右に配置し、EditText を左に配置し、画像ビューを 'leftOf' に配置します。

<EditText
    android:id="@+id/searchBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="@string/search"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/searchButton"
    android:textStyle="italic|normal"
    android:typeface="normal"
    android:singleLine="true"
    android:ellipsize="end" />

<ImageButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentRight="true"
    android:background="@drawable/search_button_selector"/>

また、 ではなくImageButtonを使用するイメージを設定する必要があります。背景を透明色に設定して、デフォルトのボタンの背景を取り除きます。android:srcandroid:background

于 2012-11-26T19:30:48.867 に答える
1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@android:drawable/ic_search_category_default" />

    <EditText
        android:id="@+id/searchBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/imageButton"
        android:ellipsize="end"
        android:hint="Search..."
        android:inputType="text"
        android:singleLine="true"
        android:textStyle="italic|normal"
        android:typeface="normal" />

</RelativeLayout>

ここに画像の説明を入力

于 2012-11-26T19:32:36.127 に答える