How does Android's setDrawingCacheEnabled() work?

前端 未结 2 972
盖世英雄少女心
盖世英雄少女心 2021-02-02 10:35

I have a UI where the root layout is a RelativeLayout. It has a number of Views, such as fields, buttons, etc.

There are also two other panels that are initially invisib

相关标签:
2条回答
  • 2021-02-02 10:54

    You may want to build your drawing cache before using it, otherwise It will give you a blank bitmap

      public void someButtonClicked(View view) {
        detailPanel.startAnimation(detailEnterAnimation);
        detailPanel.setVisibility(View.VISIBLE);
        detailPanel.setDrawingCacheEnabled(true);
        detailPanel.buildDrawingCache();  //may be you need to add this?
      }
    
    0 讨论(0)
  • 2021-02-02 11:04

    From Android documentation (http://developer.android.com/reference/android/view/View.html#setDrawingCacheEnabled%28boolean%29):

    Enabling the drawing cache is similar to setting a layer when hardware acceleration is turned off. When hardware acceleration is turned on, enabling the drawing cache has no effect on rendering because the system uses a different mechanism for acceleration which ignores the flag. If you want to use a Bitmap for the view, even when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint) for information on how to enable software and hardware layers.

    Maybe this is your case?

    0 讨论(0)
提交回复
热议问题