简体   繁体   中英

Update android view upon changing child view visibility immediatelly

I have an view, that is a 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); . How should I invalidate the view immediatelly? Neither of the methods I used after icon.setVisibility(View.VISIBLE); did not work.

It won't actually become visible until after it has gone through an onMeasure and an onDraw. Until onMeasure it doesn't know its height, until onDraw it doesn't have a cache. You're going to have to do this after the draw occurs. There's no way to make it happen immediately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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