Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 两个按钮并排显示背景图像_Android - Fatal编程技术网

Android 两个按钮并排显示背景图像

Android 两个按钮并排显示背景图像,android,Android,我想要两个并排的大按钮。它们应占据整个屏幕的宽度(即每个宽度的一半)。我希望按钮的背景包含一个图像(将从比按钮大得多的源图像中缩小)。我希望按钮的高度由图像的纵横比决定。最好都用xml完成。能做到吗 我尝试了以下方法,结果发现按钮看起来是方形的,尽管图像比它们的高度宽很多(而且两个图像的尺寸相同) 尝试使用图像按钮我相信它们会根据显示图像的大小进行缩放。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andr

我想要两个并排的大按钮。它们应占据整个屏幕的宽度(即每个宽度的一半)。我希望按钮的背景包含一个图像(将从比按钮大得多的源图像中缩小)。我希望按钮的高度由图像的纵横比决定。最好都用xml完成。能做到吗

我尝试了以下方法,结果发现按钮看起来是方形的,尽管图像比它们的高度宽很多(而且两个图像的尺寸相同)


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


<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>

我会使用
ImageView
,并将clickable属性设置为true。然后,通过设置
onClickListener
,您可以将其视为
按钮,但它会考虑图像的纵横比,而不会像使用
ImageButton
那样添加灰色边框

您尝试过这个吗?只是添加了我的非工作代码。遗憾的是,Button不允许您设置scaletype(这对于ImageButton来说很简单)。ImageButton是一个选项,还是您需要设置文本?ImageButton是一个选项在这种情况下,创建一个ImageButton并将scaletype设置为内部居中。在我看来,这些圆看起来相当椭圆。
<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>