android - 為 AppBarLayout 設置的背景圖片 TransitionDrawable 為什么只在第一次打開的時候有效?
問題描述
預期的效果是點擊用戶頭像后使用 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]。
請問這個問題應該怎么解決?是因為頭像圖片被緩存引起了什么問題嗎?
問題解答
回答1:會不會是因為你點返回鍵后 drawables[0] = mAppBarLayout.getBackground();得到的drawable就是你之前設置的TransitionDrawable
回答2:打斷點調試下
回答3:目測是圖片緩存,不過你可以自己先不進行網絡請求下載圖片,設置個本地圖片替代網絡圖片進行測試下。
回答4:動畫時間調長一點呢?
回答5:這上面用到的模糊類StackBlur,是開源的嗎? 求地址
相關文章:
1. nignx - docker內nginx 80端口被占用2. docker網絡端口映射,沒有方便點的操作方法么?3. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?4. docker綁定了nginx端口 外部訪問不到5. docker不顯示端口映射呢?6. angular.js - angular內容過長展開收起效果7. java - 為什么此私有靜態變量能被訪問呢?8. fragment - android webView 返回后怎么禁止重新渲染?9. php - mysql 模糊搜索問題10. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?
