读书人

ImageButton施用

发布时间: 2012-08-29 08:40:14 作者: rapoo

ImageButton应用
main.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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageButton android:src="@drawable/selector" android:layout_height="wrap_content" android:id="@+id/imageButton1" android:layout_width="wrap_content"></ImageButton>
<!-- android:src为图片地址 -->

</LinearLayout>


drawable目录下新建selector.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/arrow_pressed" />
<!-- 按钮按下效果 arrow_pressed和arrow_normal 为图片文件名称 -->
<item android:state_focused="true"
android:drawable="@drawable/arrow_pressed" />
<!-- 按钮获取焦点效果 -->
<item android:drawable="@drawable/arrow_normal" />
<!-- 按钮默认效果 -->

</selector>

读书人网 >图形图像

热点推荐