您的位置:首頁技術文章
文章詳情頁

android - 為 AppBarLayout 設置的背景圖片 TransitionDrawable 為什么只在第一次打開的時候有效?

瀏覽:138日期:2024-09-04 15:02:38

問題描述

預期的效果是點擊用戶頭像后使用 ImageRequest 下載圖片,然后給新的 Activity AppBayLayout 背景切換設置一個過渡效果,大致的實現代碼如下:

mQueue = CustomVolleyRequestQueue.getInstance(getApplicationContext()) .getRequestQueue();mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);ImageRequest imageRequest = new ImageRequest(mProfile.getString('profile_image_url'), new Response.Listener<Bitmap>() { @Override public void onResponse(Bitmap response) {Drawable[] drawables = new Drawable[2];drawables[0] = mAppBarLayout.getBackground();drawables[1] = new BitmapDrawable(getResources(), StackBlur.blur(response, 20, false));TransitionDrawable trans = new TransitionDrawable(drawables);mAppBarLayout.setBackground(trans);trans.startTransition(400); }}, 0, 0, null, null, null);mQueue.add(imageRequest);

現在遇到的問題時第一次點擊用戶頭像啟動用戶頁面 Activity 可以正確看到過渡效果,按返回鍵彈出之后再次點擊同一個用戶頭像就不再顯示過渡效果了,而是直接由 drawables[0] 變為 drawables[1]。

android - 為 AppBarLayout 設置的背景圖片 TransitionDrawable 為什么只在第一次打開的時候有效?

請問這個問題應該怎么解決?是因為頭像圖片被緩存引起了什么問題嗎?

問題解答

回答1:

會不會是因為你點返回鍵后 drawables[0] = mAppBarLayout.getBackground();得到的drawable就是你之前設置的TransitionDrawable

回答2:

打斷點調試下

回答3:

目測是圖片緩存,不過你可以自己先不進行網絡請求下載圖片,設置個本地圖片替代網絡圖片進行測試下。

回答4:

動畫時間調長一點呢?

回答5:

這上面用到的模糊類StackBlur,是開源的嗎? 求地址

相關文章:
国产综合久久一区二区三区