android - 為 AppBarLayout 設(shè)置的背景圖片 TransitionDrawable 為什么只在第一次打開的時(shí)候有效?
問題描述
預(yù)期的效果是點(diǎn)擊用戶頭像后使用 ImageRequest 下載圖片,然后給新的 Activity AppBayLayout 背景切換設(shè)置一個(gè)過渡效果,大致的實(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)在遇到的問題時(shí)第一次點(diǎn)擊用戶頭像啟動(dòng)用戶頁面 Activity 可以正確看到過渡效果,按返回鍵彈出之后再次點(diǎn)擊同一個(gè)用戶頭像就不再顯示過渡效果了,而是直接由 drawables[0] 變?yōu)?drawables[1]。

請(qǐng)問這個(gè)問題應(yīng)該怎么解決?是因?yàn)轭^像圖片被緩存引起了什么問題嗎?
問題解答
回答1:會(huì)不會(huì)是因?yàn)槟泓c(diǎn)返回鍵后 drawables[0] = mAppBarLayout.getBackground();得到的drawable就是你之前設(shè)置的TransitionDrawable
回答2:打斷點(diǎn)調(diào)試下
回答3:目測(cè)是圖片緩存,不過你可以自己先不進(jìn)行網(wǎng)絡(luò)請(qǐng)求下載圖片,設(shè)置個(gè)本地圖片替代網(wǎng)絡(luò)圖片進(jìn)行測(cè)試下。
回答4:動(dòng)畫時(shí)間調(diào)長(zhǎng)一點(diǎn)呢?
回答5:這上面用到的模糊類StackBlur,是開源的嗎? 求地址
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. 我何時(shí)應(yīng)該在Java中使用JFrame.add(component)和JFrame.getContentPane()。add(component)4. docker - 如何修改運(yùn)行中容器的配置5. docker鏡像push報(bào)錯(cuò)6. html5和Flash對(duì)抗是什么情況?7. javascript - 請(qǐng)指條明路,angular的$event,在select中卻是undefined?8. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!9. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。10. phpstudy8.1沒集成mysql-front

網(wǎng)公網(wǎng)安備