简体   繁体   English

立即更改子视图的可见性时更新android视图

[英]Update android view upon changing child view visibility immediatelly

I have an view, that is a RelativeLayout. 我有一个观点,那就是RelativeLayout。 Inside that layout, there is an image, that has visibility set to gone by default. 在该布局内,有一个图像,其可见性默认设置为“消失”。 What I want to achieve is to change visibility to visible programmatically and after that make a view snapshot, draw it to canvas. 我要实现的是通过编程将可见性更改为可见,然后创建视图快照,然后将其绘制到画布上。

    View icon = v.findViewById(android.R.id.icon2);
    if (icon != null) {
        icon.setVisibility(View.VISIBLE);
        v.invalidate();
        v.forceLayout();
        icon.invalidate();
        icon.refreshDrawableState();
    }

.... ....

    v.setDrawingCacheEnabled(true);
    mFloatBitmap = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false);

The resulting bitmap does not contain changes icon.setVisibility(View.VISIBLE); 生成的位图不包含更改icon.setVisibility(View.VISIBLE); . How should I invalidate the view immediatelly? 我应该如何立即使视图无效? Neither of the methods I used after icon.setVisibility(View.VISIBLE); icon.setVisibility(View.VISIBLE);之后,我都不使用这两种方法icon.setVisibility(View.VISIBLE); did not work. 不工作。

It won't actually become visible until after it has gone through an onMeasure and an onDraw. 在经过onMeasure和onDraw之后,它才真正变为可见。 Until onMeasure it doesn't know its height, until onDraw it doesn't have a cache. 直到onMeasure才知道它的高度,直到onDraw才没有缓存。 You're going to have to do this after the draw occurs. 抽奖发生后,您将必须执行此操作。 There's no way to make it happen immediately. 没有办法使它立即发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM