Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.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_Xml_Drawable - Fatal编程技术网

Android 请同时参阅位图和状态列表可绘制文件

Android 请同时参阅位图和状态列表可绘制文件,android,xml,drawable,Android,Xml,Drawable,我正在设置一个xml布局,上面有一个按钮,按钮上有文本和图像。为了使图像看起来没有拉伸,我参考了位图xml文件并调整了图像的重力。我还想在用户单击按钮时更改按钮上的图像。为此,我有一个状态列表xml文件。提到这两个组件时,它们各自都能正常工作,但我似乎只能一次完成一个。有没有一种方法可以引用多个可绘制文件,或者将它们合并为一个文件 homescreen.xml <Button android:id="@+id/bHome" android:layout_width="fill_parent

我正在设置一个xml布局,上面有一个按钮,按钮上有文本和图像。为了使图像看起来没有拉伸,我参考了位图xml文件并调整了图像的重力。我还想在用户单击按钮时更改按钮上的图像。为此,我有一个状态列表xml文件。提到这两个组件时,它们各自都能正常工作,但我似乎只能一次完成一个。有没有一种方法可以引用多个可绘制文件,或者将它们合并为一个文件

homescreen.xml

<Button
android:id="@+id/bHome"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_weight="2"
android:background="@drawable/homebutton"
android:text="Home"
android:textColor="#FFFFFF"
android:gravity="bottom|center">
</Button>    

homebutton.xml

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/homeimage"
android:gravity="center"/>

homebuttonclicked.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/homeclicked" android:state_pressed="true" ></item>
<item android:drawable="@drawable/homeclicked" android:state_focused="true"></item>
<item android:drawable="@drawable/home"></item>
</selector>

为您提供了为所需的每个按钮状态(包括正常状态和按下状态)列出多个可绘图项的可能性。按照此文档资源创建适当的状态列表,并将其用作图像的背景。希望这有帮助