相关疑难解决方法(0)

Android 2.1 View的getDrawingCache()方法始终返回null

我正在使用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时行为是否相同?

null android drawing caching view

13
推荐指数
3
解决办法
2万
查看次数

TextView(getDrawingCache)中的位图始终为null

我试图提取与显示的TextView实例关联的位图,但它总是返回一个空值.我究竟做错了什么?我应该使用textview.draw(canvas)吗?

    TextView textview = (TextView) findViewById(R.id.text_title);
    textview.setDrawingCacheEnabled(true);
    textview.buildDrawingCache();        
    Bitmap bmp = textview.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)

android view

6
推荐指数
2
解决办法
7484
查看次数

启用滚动时,调用`getDrawingCache`返回null

这段代码中缺少什么?这个代码适用于ICS.在API 8上,滚动出现,一些内容超出屏幕.在这种情况下如何获得绘图缓存?

码:

TableLayout page = (TableLayout) findViewById(R.id.page);
page.setDrawingCacheEnabled(true);
page.buildDrawingCache();

// getDrawingCache returns null...
Bitmap pageBmp = Bitmap.createBitmap(page.getDrawingCache(true));
page.destroyDrawingCache();
page.setDrawingCacheEnabled(false);
Run Code Online (Sandbox Code Playgroud)

android view drawingcache

6
推荐指数
1
解决办法
7915
查看次数

标签 统计

android ×3

view ×3

caching ×1

drawing ×1

drawingcache ×1

null ×1