如何获得布局xml文件的路径? [英] How to get layout xml file path?

查看:106
本文介绍了如何获得布局xml文件的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示的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 is normal-mdpi, I need to display "Path is: /res/layout-normal-mdpi" or if the mobile phone is normal-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 by

TextView 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆