9

我需要参考单独的 XML 文件,它是 FrameLayout,但我不知道该怎么做,这段代码不起作用:

FrameLayout desktopFrameLayout = (FrameLayout) findViewById(R.id.desktopsFramelayout);
desktopFrameLayout.setDrawingCacheEnabled(true);
desktopFrameLayout.buildDrawingCache();
Bitmap bitmap = desktopFrameLayout.getDrawingCache();
4

1 回答 1

17

为此,您必须使用膨胀视图。

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.mylayout, null);

FrameLayout item = (FrameLayout ) view.findViewById(R.id.desktopsFramelayout);
于 2013-03-05T10:57:06.713 回答