Android - 图像按钮(XML)不起作用?
问题描述:
我在绘制文件夹中三幅图像,和一个XML图像按钮代码:Android - 图像按钮(XML)不起作用?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">\
<item android:state_pressed="true"
android:drawable="@drawable/happycarrot" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/largerunicornbutton2" /> <!-- focused -->
<item android:drawable="@drawable/largerunicornbutton" /> <!-- default -->
</selector>
在我的布局文件夹中,我有我的主要XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:src="@drawable/button"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
></ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
当我在emualtor运行我只得到第一张图片。它什么都不做。我能做些什么来解决这个问题吗?
答
使用Linearlayout而不是相对的修复了问题。