Android开参考布局code [英] android get reference to layout in code
本文介绍了Android开参考布局code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要引用单独的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);
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);
这篇关于Android开参考布局code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文