android ImageView 視屏幕情況 使圖片在限定范圍內進行縮放顯示


例如圖片默認大小為: 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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM