1、ImageView繼承View組件,不單單用于顯示圖片,用 XML代碼 編寫的Drawable也可以顯示出來。
其中的XML屬性 android:scaleType(設置圖片如何縮放或移動以適應ImageView的大小) 有很多的屬性值,如:matrix(使用矩形方式進行縮放)fitXY(對圖片橫向`縱向縮放)center(圖片放在ImageView中間)等等…
下面是XML代碼:<ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/textView1"android:scaleType="fitCenter"android:src="@drawable/ic_launcher"android:layout_toRightOf="@+id/textView1" />
?
2、ImageButton,與前面講的Button的區別在于Button生成的按鈕上顯示文字,而ImageButton顯示圖片,對它設置android:text屬性是沒用的。
下面是XML代碼:使用android:src 自定義Drawable對象<ImageButtonandroid:id="@+id/imageButton1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/button_selector" />補充:drawable的XML文件在前面的筆記(二)也有寫過Android基本組件(筆記二)<?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|d1"/><!– 指定按鈕松開時的圖片 –><item android:state_pressed="false"android:drawable="drawable|d2"/></selector>
?
3、ZoomButton代表“放大”,“縮小”兩個按鈕,android默認提供了btn_minus,btn_plus兩個drawable資源。<ZoomButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn_zoom_down"android:src="@android:drawable/btn_minus" /><ZoomButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn_zoom_up"android:src="@android:drawable/btn_plus" />Android基本組件(三)
?
4、QuickContactBadge,繼承了ImageView,可通過android src 添加圖片。增加的額外功能是該圖片可以關聯到手機中指定的聯系人,當用戶點擊該圖片時系統將會打開相應聯系人的聯系方式界面。<QuickContactBadgeandroid:id="@+id/badge"android:layout_height="wrap_content"android:layout_width="wrap_content"android:src="@drawable/ic_launcher"/>
轉載 - 編程知識