ImageView 加載過大圖片時就會閃
代碼非常簡單 直接新建一個工程 扔上 下面的xml 不用加其它代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--用一個view來看色 比較明顯-->
<ImageView
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_margin="16dp"
android:src="https://bbs.csdn.net/topics/#FFA382"/>
<!--一個scrollview 來滾動-->
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--一個image view 來顯示大一點的圖片 這時就會有bug-->
<ImageView
android:id="@+id/id_glide_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="16dp"
android:background="@drawable/big_image"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
布局很簡單
就是 scrollview 里放了一個image view 用來加載一張大一點的圖(也不大 就 800x800) ,然后 滾動scrollview 就可以看my_toolbar會閃
機型 紅米
都會這樣 有人知道為什么嗎?
uj5u.com熱心網友回復:
試試用gliduj5u.com熱心網友回復:
看起來這個圖片是本地的資源圖片,什么處理都不做,而且資源圖片放置的目錄和當前手機螢屏分比率相同的情況下產生的記憶體是2MB(800*800*4)。如果放置的檔案夾對應的螢屏解析度比當前手機的還低,那么又會進行一次放大。
相關計算可以參考https://blog.csdn.net/stven_king/article/details/105677102這篇文章
uj5u.com熱心網友回復:
沒用 其實我就是用glide加載時發現的 一開始 以為是glide的問題,去掉了 glide 還是一樣反復測了好幾天后 發現只要 scrollview+imageview就能復現了
uj5u.com熱心網友回復:
的確就是什么也不處理,(我去掉了所有代碼后還是存在問題,就干脆另建一工程試了,都不用改java代碼) 實際上就順便網上拿的一張圖片 不管是 小于手機解析度 還是大于 都會有這個問題。。仔細看就會發現一閃一閃的 很煩人 ,然道沒人遇到這個問題嗎?手頭上兩臺不同版本的紅米都這樣,試了好幾天 快捉狂了
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/266493.html
標籤:Android
