我如何检测其布局被选中的Andr​​oid在我的应用程序? [英] How can I detect which layout is selected by Android in my application?

查看:323
本文介绍了我如何检测其布局被选中的Andr​​oid在我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有不同的资源文件夹三种不同版式的活动。例如:

Assume I have an activity with three different layouts in different resource folders. For example:

布局陆/ my_act.xml
  布局XLARGE / my_act.xml
  布局XLARGE陆/ my_act.xml

layout-land/my_act.xml
layout-xlarge/my_act.xml
layout-xlarge-land/my_act.xml

在不同设备和不同位置其中之一被选中的Andr​​oid。照片我怎样才能找出哪一个被选中的编程的?

In different devices and different positions one of them is selected by Android.
How can I find out which one is selected programmatically?

Android的是否有返回这些布局的程序的任何API?

Does Android have any API that returns these layouts to the program?

修改格雷厄姆Borland的解决方案有我在提到某些情况下的一个问题注释。

Edit: Graham Borland's solution has a problem in some situations that I mentioned in the comments.

推荐答案

您可以创建一个值时─<配置> 目录为每个受支持的配置。在每个这些目录中,创建一个的strings.xml 有一个 selected_configuration 字符串,它描述了当前的配置。在运行时,提取使用标准的getString 方法,它会做配置的分辨率,为您和返回正确的字符串配置的字符串。这是未经测试。

You could create a values-<config> directory for each of your supported configurations. Inside of each of those directories, create a strings.xml with a single selected_configuration string which describes the current configuration. At runtime, fetch the string using the standard getString method, which will do the configuration resolution for you and return the correct string for the configuration. This is untested.

这篇关于我如何检测其布局被选中的Andr​​oid在我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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