gpt4 book ai didi

android - 从布局创建可绘制对象

转载 作者:太空狗 更新时间:2023-10-29 15:49:03 24 4
gpt4 key购买 nike

有没有办法从布局生成可绘制对象?

其实我的初始布局需要裁剪一部分,我的想法是将布局转换为drawable对象,然后裁剪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);
}

关于android - 从布局创建可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5950995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com