创建一个从布局绘制 [英] 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.
推荐答案
一个简单的版本:
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);
}
这篇关于创建一个从布局绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文