Imp*_*ion 13 null android drawing caching view
我正在使用Android 2.1并遇到以下问题:使用方法View.getDrawingCache()始终返回null.getDrawingCache()应返回一个Bitmap,它是View内容的表示.
示例代码:
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View view = findViewById(R.id.ImageView01);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
final Bitmap bmp = view.getDrawingCache();
System.out.println(bmp);
Run Code Online (Sandbox Code Playgroud)
}
我已经尝试了不同的方法来配置View对象以生成绘图缓存(例如View.setWillNotDraw(boolean)和View.setWillNotCacheDrawing(boolean)),但没有任何作用.
什么是正确的方式,或者我做错了什么?
PS:在实际代码中,我想在像RelativeLayout这样的ViewGroup上应用getDrawingCache().使用ViewGroup时行为是否相同?
You*_*ave 17
Bitmap screenshot;
view.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
Run Code Online (Sandbox Code Playgroud)
您需要Bitmap.createBitmap(view.getDrawingCache());通过getDrawingCache()回收来接收引用的位图.
使用
onLayout(x, y, width, height);
Run Code Online (Sandbox Code Playgroud)
对于前:
onLayout(0, 0, 100, 100);
Run Code Online (Sandbox Code Playgroud)
在调用getDrawingCache之前
| 归档时间: |
|
| 查看次数: |
20315 次 |
| 最近记录: |