Create drawable from layout

后端 未结 1 1791
死守一世寂寞
死守一世寂寞 2021-01-07 06:03

Is there a way to generate a drawable object from a layout?

In fact, I need a cropped part of my initial layout, and my idea is to transform the layout into a drawab

相关标签:
1条回答
  • 2021-01-07 06:28

    A simple version:

    Bitmap snapshot = null;
        Drawable drawable = null;
        yourView.setDrawingCacheEnabled(true);
        yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); //Quality of the snpashot
        try {
            snapshot = Bitmap.createBitmap(yourView.getDrawingCache(), sizes and stuff); // You can tell how to crop the snapshot and whatever in this method
            drawable = new BitmapDrawable(snapshot)
        } finally {
            yourView.setDrawingCacheEnabled(false);
        }
    
    0 讨论(0)
提交回复
热议问题