Android View.getDrawingCache returns null, only null

后端 未结 10 939
遇见更好的自我
遇见更好的自我 2020-11-22 13:06

Would anyone please try to explain to me why

public void addView(View child) {
  child.setDrawingCacheEnabled(true);
  child.setWillNotCacheDrawing(false);
          


        
10条回答
  •  情深已故
    2020-11-22 13:45

    The basic reason one gets nulls is that the view is not dimentioned. All attempts then, using view.getWidth(), view.getLayoutParams().width, etc., including view.getDrawingCache() and view.buildDrawingCache(), are useless. So, you need first to set dimensions to the view, e.g.:

    view.layout(0, 0, width, height);
    

    (You have already set 'width' and 'height' as you like or obtained them with WindowManager, etc.)

提交回复
热议问题