0

2 つの大きなボタンを並べて配置したいと考えています。それらは画面全体を占有する必要があります (つまり、それぞれの幅の半分)。ボタンの背景に画像を含める必要があります(ボタンよりもはるかに大きいソース画像から縮小されます)。ボタンの高さを画像の縦横比で指定したい。できれば、すべて xml で行います。それはできますか?

次のことを試してみましたが、画像の幅が高さよりもはるかに大きいにもかかわらず、ボタンが正方形に見えることがわかりました (両方の画像の寸法は同じです)。

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

    <Button
        android:id="@+id/rep_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:background="@drawable/repeating"
        android:text="" />

    <Button
        android:id="@+id/oneoff_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:background="@drawable/oneoff"
        android:text="" />

</LinearLayout>
4

3 に答える 3

0

を使用しImageView、clickable属性をtrueに設定します。Button次に、を設定することでそれをaのように扱うことができますが、 。の場合のようonClickListenerに灰色の境界線を追加することなく、画像のアスペクト比を処理しImageButtonます。

于 2012-08-28T19:13:01.877 に答える
0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >

<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/retro_blue_background"
    android:text="Übernehmen" >

</Button>

<Button
    android:id="@+id/Button02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/retro_blue_background"
    android:text="Abbrechen" >

</Button>

</LinearLayout>

それはあなたが望むものですか?

于 2012-08-28T18:49:34.003 に答える
0

ImageButton表示されている画像のサイズに基づいてスケーリングされると思います。

于 2012-08-28T18:14:40.620 に答える