Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does Android's setDrawingCacheEnabled() work?
    text
    copied!<p>I have a UI where the root layout is a RelativeLayout. It has a number of Views, such as fields, buttons, etc.</p> <p>There are also two other panels that are initially invisible. When the user clicks a button, one of these panels slides in from the left, another slides in from the bottom. The problem is the frame rate is pathetic on a Nexus S.</p> <p>I want to use setDrawingCacheEnabled(true) in order to (I hope) speed up the animation of these two panels. As a simplified example, here is roughly how I slide in one of these panels. I'll call it "detailPanel".</p> <pre><code>public class MyActivity extends Activity { // Initially invisible. private View detailPanel; // A simple slide animation. private Animation detailEnterAnimation; ... public void someButtonClicked(View view) { detailPanel.startAnimation(detailEnterAnimation); detailPanel.setVisibility(View.VISIBLE); detailPanel.setDrawingCacheEnabled(true); } } </code></pre> <p>Now in the DetailPanel I try to use the cache. I was hoping that bitmap rendering via the cache would improve performance:</p> <pre><code>public class DetailPanel extends LinearLayout { public void draw(Canvas canvas) { Bitmap cache = getDrawingCache(); if (cache != null) { canvas.drawBitmap(cache, 0, 0, null); } else { super.draw(canvas); } } } </code></pre> <p>The Bitmap is non-null and is the right size, but it is completely black.</p> <p>Why is my bitmap black? That code may be obscenely wrong; I've tried a million different things and just cannot figure it out.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload