0

画面の右側にボタンがあり、ボタンの左側にあるすべての場所に編集テキストが必要です。どのようにできるのか?

このxmlは、画面の左側にボタンを表示しますが、その前には何も表示しません:/

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>

    <Button 
        android:id="@+id/index_bouton_recherche"
        android:layout_width="45px"
        android:layout_height="45px"
        android:background="@drawable/loupe"
    />

    <EditText 
        android:id="@+id/index_champs_recherche"
        android:layout_width ="fill_parent"
        android:layout_height="wrap_content"
        android:maxLines="1" 
        android:layout_toLeftOf="@id/index_bouton_recherche"
    />
4

2 に答える 2

1

これを試して

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
>

    <Button 
        android:id="@+id/index_bouton_recherche"
        android:layout_width="45px"
        android:layout_height="45px"
        android:background="@drawable/loupe"
    />

    <EditText 
        android:id="@+id/index_champs_recherche"
        android:layout_width ="fill_parent"
        android:layout_height="wrap_content"
        android:maxLines="1" 
        android:layout_toLeftOf="@id/index_bouton_recherche"
        android:layout_weight="1"
    />
</LinearLayout>
于 2011-08-16T09:36:09.300 に答える
1

これを行う必要がある場合は、xml 属性を使用LinearLayoutlayout_weightます。この XML はあなたの問題を解決します:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
>
    <EditText 
        android:id="@+id/index_champs_recherche"
        android:layout_width ="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:maxLines="1" 
    />
    <Button 
        android:id="@+id/index_bouton_recherche"
        android:layout_width="45px"
        android:layout_height="45px"
        android:background="@drawable/loupe"
    />
</LinearLayout>

これlayout_width="0dp"は、最初はビューにスペースが必要ないことを意味します。Button はwrap_contentであるため、スペースのみが必要です。このlayout_weight属性は後で適用され、レイアウト上の残りのスペースを共有します (方向 = 水平の幅、垂直の高さ)。デフォルトのビュー ウェイトは 0 であるため、1 を指定すると、EditText は残りのスペースの 100% を占有します。

于 2011-08-16T09:52:49.993 に答える