如何获得布局xml文件的路径? [英] How to get layout xml file path?
问题描述
我要显示的setContentView(R.layout.main)用于布局的路径;
。因此,如果手机是正常MDPI
,我需要显示路径为:/ RES /布局正常MDPI,或者如果手机是正常华电国际
,我需要一个文本路径是:/ RES /布局正常华电国际。
基本上,我需要知道哪些布局文件加载和它的路径。
您可以在XML结果中添加隐藏文本视图具有相应文件夹名称
通过搜索
TextView的路径=(TextView中)findViewbyid(R.id.hiddentextview);
字符串s = path.gettext()的ToString()。
请确保文本视图的所有ID是一样的
示例
如果您的XML是`在隐藏的TextView硬code`正常mdpi`正常mdpi`
如果您的XML是`在隐藏的TextView硬code`大mdpi`大mdpi`
块引用>I need to display the path of layout used in
setContentView(R.layout.main);
. So if the mobile phone isnormal-mdpi
, I need to display "Path is: /res/layout-normal-mdpi" or if the mobile phone isnormal-hdpi
, I need a text "Path is: /res/layout-normal-hdpi".I basically need to know which layout file was loaded and its path.
解决方案You can add a Hidden Text View with corresponding Folder names in the xml
Get the String in the text view byTextView path = (TextView)findViewbyid(R.id.hiddentextview); String s = path.gettext().tostring();
Make sure that all the id's of the text view are same Example
if your xml is in `normal-mdpi` in hidden textview hard code `normal-mdpi` if your xml is in `large-mdpi` in hidden textview hard code `large-mdpi`
这篇关于如何获得布局xml文件的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!