解決scrollview嵌套ImageView時,出現除頂部和底部黑塊的問題


最近一個項目中,從網上下載一個圖片,然后展示給用戶看,那個圖片本來是iphone里的,拿到android上來,一拉伸就出問題了,scrollview的頂部和底部出現了奇怪的黑塊,如圖:

在網上找了很資料都沒解決,后來在一個外國網站找到結果,分享一下。

代碼:

 

<?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"
    >
<ScrollView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    >
    <ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/demo"
     android:adjustViewBounds="true"
    android:scaleType="centerInside"></ImageView>
    </ScrollView>
</LinearLayout>

android:adjustViewBounds="true"這句很關鍵

奉送美女圖片一張:/Files/ProgramBull/demo.jpg

 


免責聲明!

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



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