开发者

Create drawable from layout

Is there a way to generate a drawable object 开发者_运维百科from a layout?

In fact, I need a cropped part of my initial layout, and my idea is to transform the layout into a drawable object and then to crop drawable.


A simple version:

Bitmap snapshot = null;
    Drawable drawable = null;
    yourView.setDrawingCacheEnabled(true);
    yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); //Quality of the snpashot
    try {
        snapshot = Bitmap.createBitmap(yourView.getDrawingCache(), sizes and stuff); // You can tell how to crop the snapshot and whatever in this method
        drawable = new BitmapDrawable(snapshot)
    } finally {
        yourView.setDrawingCacheEnabled(false);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜