SORU
26 ŞUBAT 2010, Cuma


Android Görüntüleyin.getDrawingCache null, sadece null

Herkes neden bana açıklamak için deneyin

public void addView(View child) {
  child.setDrawingCacheEnabled(true);
  child.setWillNotCacheDrawing(false);
  child.setWillNotDraw(false);
  child.buildDrawingCache();
  if(child.getDrawingCache() == null) { //TODO Make this work!
    Log.w("View", "View child's drawing cache is null");
  }
  setImageBitmap(child.getDrawingCache()); //TODO MAKE THIS WORK!!!
}

Her ZAMAN çizim önbellek boş günlükleri ve bitmap null olarak ayarlar?

Aslında önbellek ayarlanır önce görünüm çizmek zorunda mıyım?

Teşekkürler!

CEVAP
6 Ocak 2011, PERŞEMBE


Ayrıca bu sorunu yaşıyordum ve bu cevap buldu

v.setDrawingCacheEnabled(true);

// this is the important code :)  
// Without it the view will have a dimension of 0,0 and the bitmap will be null          
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 

v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • hytchme

    hytchme

    9 Mart 2014
  • jesiel santos

    jesiel santo

    15 Ocak 2009
  • Joshua Kywn

    Joshua Kywn

    17 Mayıs 2010