找回密碼
 註冊
搜索
查看: 12513|回復: 0

[Android] ImageButton 大小調整

[複製鏈接]
發表於 2014-1-28 09:16:15 | 顯示全部樓層 |閱讀模式
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
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-4-20 04:07 , Processed in 0.015380 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表