安卓:如何访问取决于屏幕密度的XML不同的布局 [英] Android: How to access different layouts depending of screen density in XML

查看:208
本文介绍了安卓:如何访问取决于屏幕密度的XML不同的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何得到不同的XML布局文件,根据画面的密度进行读取。

当我进入一个布局文件和设置,以便它有几个按钮和将其设置为一个特定位置

现在,当我改变在模拟器另一个屏幕密度的位置变化。这是应该发生什么,我understand-,但我怎样的程序来使用不同的布局视密度?

我一直在阅读上的Andr​​oid开发人员。关于如何开发不同的屏幕,但我没有得到这那里的例子页面。

我一直在使用的尺寸DP / DIP所以没有必要认为=)


解决方案

您可以通过为每个非标准屏幕尺寸创建布局做了,

这里

您可以找到 的如何做到这一点。

  RES /布局/ my_layout.xml //适用于布局进行正常的屏幕尺寸(默认)
RES /布局小/ my_layout.xml //适用于布局屏幕尺寸小
RES /布局大/ my_layout.xml //适用于布局大尺寸屏幕
RES /布局XLARGE / my_layout.xml //适用于布局超大屏幕尺寸
RES /布局XLARGE土地/ my_layout.xml //适用于布局横向特大型RES /绘制-MDPI / my_icon.png //适用位图中密度
RES /绘,华电国际/ my_icon.png //适用位图高密度
RES /绘制-xhdpi / my_icon.png //适用位图特高密度

这意味着你应该创建命名为(布局,布局小,布局大,布局XLARGE,布局XLARGE土地)在res文件夹中。

不是创建为每一个有相同名称的主XML。

I am wondering how to get different XML layout files to be read depending of density of the screen.

Now when I enter a layout file and set to so that it has a couple of buttons and have them set to a specific position, the position changes when I change to another screen density in the emulator. This is what should be happening what i understand- but How do I get the program to use different layouts depending of densities?

I have been reading on android dev. page on how to develop for different screens, but I didn't get the examples which were there.

I have been using dp/dip on sizes so no need to suggest that =)

解决方案

you can do it by creating a layout for each standart screen sizes,

you can find here how to do it.

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

it means you should create sub-directory named as ("layout", "layout-small","layout-large","layout-xlarge","layout-xlarge-land") in res folder.

than create a main xml for each one with the same name.

这篇关于安卓:如何访问取决于屏幕密度的XML不同的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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