Android开参考布局code布局、Android、code

2023-09-07 09:18:21 作者:优质小年轻

我需要引用单独的XML文件至极是的FrameLayout,但我无法弄清楚如何做到这一点,这code不工作:

 的FrameLayout desktopFrameLayout =(的FrameLayout)findViewById(R.id.desktopsFramelayout);
        desktopFrameLayout.setDrawingCacheEnabled(真正的);
        desktopFrameLayout.buildDrawingCache();
        点阵位图= desktopFrameLayout.getDrawingCache();
 

解决方案

有关,你必须使用夸大观点。

  LayoutInflater吹气=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
查看查看= inflater.inflate(R.layout.mylayout,NULL);

的FrameLayout项目=(的FrameLayout)view.findViewById(R.id.desktopsFramelayout);
 
androidCode的个人空间 OSCHINA

I need to get reference to separate XML file wich is FrameLayout but I can't figure out how to do it ,this code doesn't work:

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

解决方案

For that you have to use inflate view.

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

FrameLayout item = (FrameLayout ) view.findViewById(R.id.desktopsFramelayout);