ImageButton 大小調整
1.背景透明,依圖片大小縮放<ImageButton
android:id="@+id/Button01"
android:scaleType="fitcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cropToPadding="false"
android:paddingLeft="10dp"
android:background="@android:color/transparent"
android:src="@drawable/eye" />2.圖片無法調整大小,利用background取代src使用即可
android:src="@drawable/eye" 改用 android:background="@drawable/eye"
3.使用background,並指向一個xml去定義圖片
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/skin" />skin.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- <item android:drawable="@drawable/button_disabled" android:state_enabled="false"/> -->
<item android:drawable="@drawable/button_pressed" android:state_pressed="true"/>
<!-- <item android:drawable="@drawable/button_focused" android:state_focused="true"/> -->
<item android:drawable="@drawable/button_normal"/>
</selector>
Reference:
ImageButton in Android
http://stackoverflow.com/questions/3318629/imagebutton-in-android
Tutorial: Buttons with (niceley) stretched background
http://www.anddev.org/tutorial_b ... ckground-t4369.html
頁:
[1]