Q:

getDrawingCache() in another layout

I have code like this:
 protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);
 }

...
 FrameLayout frameLayout = (FrameLayout)findViewById(R.id.rLayout_main);

 frameLayout.setDrawingCacheEnabled(true);

 frameLayout.buildDrawingCache(true);

 Bitmap bitmap = frameLayout.getDrawingCache();

The bitmap NOT null when id.rLayout_main in layout activity_main. 
But when I replace id.rLayout_main to id.layout_report, it's not in layout activity_main, it's in layout report. I change code like this:
 FrameLayout viewGroup= new FrameLayout(context);

 LayoutInflater inflaters = LayoutInflater.from(context);

 View root = inflaters.inflate(R.layout.report,viewGroup, true);

 FrameLayout frameLayout = (FrameLayout)root.findViewById(R.id.layout_report);

 frameLayout.setDrawingCacheEnabled(true);

 frameLayout.buildDrawingCache(true);

 Bitmap bitmap = frameLayout.getDrawingCache();

This time, bitmap always return NULL. Please Help Me!!!

A:

I think the problem is that your view has been inflated but it has not been drawn yet. That is why the bitmap is null. What if you do this:
FrameLayout viewGroup = (FrameLayout)findViewById(R.id.rLayout_main);
LayoutInflater inflaters = LayoutInflater.from(context);
View root = inflaters.inflate(R.layout.report,viewGroup, true);
FrameLayout frameLayout = (FrameLayout)root.findViewById(R.id.layout_report);
frameLayout.setDrawingCacheEnabled(true);
frameLayout.buildDrawingCache(true);
Bitmap bitmap = frameLayout.getDrawingCache();

