search

Home  >  Q&A  >  body text

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]。

请问这个问题应该怎么解决?是因为头像图片被缓存引起了什么问题吗?

迷茫迷茫2772 days ago673

reply all(5)I'll reply

  • PHPz

    PHPz2017-04-17 17:40:19

    Could it be because after you click the return button drawables[0] = mAppBarLayout.getBackground(); the drawable you get is the TransitionDrawable you set before

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:40:19

    Debug with break points

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:40:19

    Visually it is image caching, but you can download the image without making a network request first, and set a local image to replace the network image for testing.

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:40:19

    Can the animation time be made longer?

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 17:40:19

    Is the blur class StackBlur used above open source? Please address

    reply
    0
  • Cancelreply