例如圖片默認大小為: 380 * 380
常規處理:因界面顯示區域有限 可以使其讓其按 100 * 100 大小顯示 則圖片會縮小
則不論屏幕大小 圖片都只能這樣顯示
靈活處理:使圖片在限定范圍內進行最佳顯示
一方面 可顯示區域夠大時 限定最大不超過原始大小 不做放大顯示
另一方面 顯示區域不夠時 根據控件的可顯示范圍 進行縮放顯示
<?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">
<!-- 固定顯示大小 -->
<ImageView android:id="@+id/imageView1"
android:src="@drawable/photo2"
android:layout_height="@dimen/photoImageSizeWidth2"
android:layout_width="@dimen/photoImageSizeWidth2"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"></ImageView>
<!-- 視情況在限定范圍內進行最佳顯示 -->
<ImageView android:id="@+id/imageView2"
android:src="@drawable/photo2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="380dip" android:maxHeight="380dip"
android:layout_margin="50dip" android:scaleType="fitXY"
android:layout_gravity="center_horizontal"></ImageView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="photoImageSizeWidth2">100dip</dimen>
<dimen name="photoImageSizeHight2">100dip</dimen>
</resources>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- 固定顯示大小 -->
<ImageView android:id="@+id/imageView1"
android:src="@drawable/photo2"
android:layout_height="@dimen/photoImageSizeWidth2"
android:layout_width="@dimen/photoImageSizeWidth2"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"></ImageView>
<!-- 視情況在限定范圍內進行最佳顯示 -->
<ImageView android:id="@+id/imageView2"
android:src="@drawable/photo2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="380dip" android:maxHeight="380dip"
android:layout_margin="50dip" android:scaleType="fitXY"
android:layout_gravity="center_horizontal"></ImageView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="photoImageSizeWidth2">100dip</dimen>
<dimen name="photoImageSizeHight2">100dip</dimen>
</resources>