[Android] ImageButton 大小調整 看全部

1.背景透明,依圖片大小縮放
  1. <ImageButton
  2.     android:id="@+id/Button01"
  3.     android:scaleType="fitcenter"
  4.     android:layout_width="wrap_content"
  5.     android:layout_height="wrap_content"
  6.     android:cropToPadding="false"
  7.     android:paddingLeft="10dp"
  8.     android:background="@android:color/transparent"
  9.     android:src="@drawable/eye" />
2.圖片無法調整大小,利用background取代src使用即可
android:src="@drawable/eye" 改用 android:background="@drawable/eye"

3.使用background,並指向一個xml去定義圖片
  1. <ImageButton
  2.         android:layout_width="wrap_content"
  3.         android:layout_height="wrap_content"
  4.         android:layout_centerInParent="true"
  5.         android:background="@drawable/skin" />
skin.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
  3.     <!-- <item android:drawable="@drawable/button_disabled" android:state_enabled="false"/> -->
  4.     <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/>
  5.     <!-- <item android:drawable="@drawable/button_focused" android:state_focused="true"/> -->
  6.     <item android:drawable="@drawable/button_normal"/>
  7. </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