android - 為 AppBarLayout 設(shè)置的背景圖片 TransitionDrawable 為什么只在第一次打開的時候有效?
問題描述
預(yù)期的效果是點(diǎn)擊用戶頭像后使用 ImageRequest 下載圖片,然后給新的 Activity AppBayLayout 背景切換設(shè)置一個過渡效果,大致的實現(xiàn)代碼如下:
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);
現(xiàn)在遇到的問題時第一次點(diǎn)擊用戶頭像啟動用戶頁面 Activity 可以正確看到過渡效果,按返回鍵彈出之后再次點(diǎn)擊同一個用戶頭像就不再顯示過渡效果了,而是直接由 drawables[0] 變?yōu)?drawables[1]。
請問這個問題應(yīng)該怎么解決?是因為頭像圖片被緩存引起了什么問題嗎?
問題解答
回答1:會不會是因為你點(diǎn)返回鍵后 drawables[0] = mAppBarLayout.getBackground();得到的drawable就是你之前設(shè)置的TransitionDrawable
回答2:打斷點(diǎn)調(diào)試下
回答3:目測是圖片緩存,不過你可以自己先不進(jìn)行網(wǎng)絡(luò)請求下載圖片,設(shè)置個本地圖片替代網(wǎng)絡(luò)圖片進(jìn)行測試下。
回答4:動畫時間調(diào)長一點(diǎn)呢?
回答5:這上面用到的模糊類StackBlur,是開源的嗎? 求地址
相關(guān)文章:
1. [前端求職必看]前端開發(fā)面試題與答案精選_擴(kuò)展問題2. javascript - 在top.jsp點(diǎn)擊退出按鈕后,right.jsp進(jìn)行頁面跳轉(zhuǎn),跳轉(zhuǎn)到login.jsp3. javascript - 下面的這段算法代碼求解釋4. mac連接阿里云docker集群,已經(jīng)卡了2天了,求問?5. css3 - 在sublime text里, 如何讓emmet生成的帶前綴css屬性垂直對齊?6. javascript - js 有什么優(yōu)雅的辦法實現(xiàn)在同時打開的兩個標(biāo)簽頁間相互通信?7. java - spring-data Jpa 不需要執(zhí)行save 語句,Set字段就可以自動執(zhí)行保存的方法?求解8. android - 哪位大神知道java后臺的api接口的對象傳到前端后輸入日期報錯,是什么情況?求大神指點(diǎn)9. javascript - angular中如何創(chuàng)建一個能被不同模塊中組件都能訪問其屬性和方法的對象10. 想找個php大神仿個網(wǎng)站。
