两个按钮肩并肩与背景图象

时间:2012-08-28 17:52:35

标签: android

我希望并排有两个大按钮。它们应该占据屏幕的全部(即每个宽度的一半)。我希望按钮的背景包含一个图像(将从远大于按钮的源图像缩小)。我希望按钮的高度由图像的纵横比决定。最好全部用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>

3 个答案:

答案 0 :(得分:0)

尝试使用ImageButton我相信它们会根据所显示图像的大小进行缩放。

答案 1 :(得分: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>

Is that what you want?

答案 2 :(得分:0)

我会使用ImageView,并将clickable属性设置为true。然后,您可以通过设置Button将其视为onClickListener,但它会处理图像的宽高比,而不会像添加ImageButton那样添加灰色边框。

相关问题