有没有一种方法可以从布局中生成可绘制对象?
实际上,我需要裁剪初始布局的一部分,我的想法是将布局转换为可绘制对象,然后裁剪可绘制对象。
有没有一种方法可以从布局中生成可绘制对象?
实际上,我需要裁剪初始布局的一部分,我的想法是将布局转换为可绘制对象,然后裁剪可绘制对象。
一个简单的版本:
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);
}