不同高度的 Android 设备采用相同的布局文件夹 [英] Android devices with different height takes same layout folder

查看:16
本文介绍了不同高度的 Android 设备采用相同的布局文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个屏幕分辨率为 1280*720 像素的 Micromax AQ5000 和分辨率为 720 x 1280 像素的摩托罗拉 Moto G XT1033.我有一个名为 layout-sw360dp 的布局文件夹,我为三星 s4、s3、Micromax canvas 等设备设计等等,但此摩托罗拉设备也使用相同的布局,这会导致图像显示为扭曲.

I have a Micromax AQ5000 with Screen Resolution- 1280*720 pixels and Motorola Moto G XT1033 with resolution 720 x 1280 pixels.I have a layout folder named layout-sw360dp which I designed for devices like Samsung s4,s3,Micromax canvas etc but this Motorola device is also using the same layout and this creates the images displayed as distorted in it.

如何为小型设备(Moto g)创建文件夹我试过 layout-xhdpi 但它不起作用我如何用高度和宽度命名布局.

How can I create a folder for the small device(Moto g) I tried layout-xhdpi but it doesn't work how can I name layout with height and width.

推荐答案

嗯,从某种意义上说,android 应该根据不同的密度进行布局,但某些移动设备不属于特定密度.因此 android 将从布局目录中选择默认布局.

Well you are right in some sense android should take layout dependent on different densities but some mobile do not fall under specific density. Therefore android will pick up default layout from layout directory.

为了支持多种屏幕分辨率为不同的屏幕尺寸提供不同的布局,你可以像这样在 res 目录中创建以下目录

to support multiple screen resolution provide different layout for different screen sizes, you can make following directories in res directory like this

layout-hdpi

layout-mdpi

layout-xhdpi

layout-xxhdpi

layout-w320dp-h408dp

layout-w480dp-h800dp

layout-w480dp-h854dp

layout-w720dp-h1280dp

layout-w1080dp-h1920dp

当您在所有这些目录中提供布局时,您还将为不同尺寸提供多屏幕支持布局-w1440dp-h2560dp

when you provide layout in all this directories you will give multiple screen support for different sizes as well layout-w1440dp-h2560dp

改用dip",它们将帮助您调试布局,因为它们会尝试使多个屏幕分辨率保持一致的大小,

Use "dip" instead they will help you in debugging your layout as they will try to keep a coherent size to multiple screen resolutions,

<ImageView
            android:id="@+id/avtar_animation_11"
            android:layout_width="45dip"
            android:layout_height="45dip"
            android:src="@drawable/avtar011"/>

当您为维度提供dp"时支持多屏幕,实际上android希望您为不同的屏幕分辨率提供不同的值.让我们说下面是您的 imagview 尺寸在您的 android 项目中的 res 文件夹中创建了几个文件夹,如下所示

while supporting multiple screen when you give "dp" to dimensions, Actually android expects you to provide different values for different screen resolution. Lets say below is your imagview dimensions make few folders in res folder in your android project like these below

values-hdpi, values-mdpi, values-ldpi, values-xhdpi, values-xxhdpi

并在其中创建一个 dimens.xml 文件,并写入

and in them make a dimens.xml file each of them and write

<dimen name="image_view_width">28dp</dimen>
<dimen name="image_view_height">28dp</dimen>

既然我在这里提到了dp"而不是 dip,android 想让我跟踪不同屏幕分辨率的不同尺寸,所以我将更改 image_view_width 和 image_view_height 值在 dimens.xml 所在的单独值文件夹中.确保您的 dp 值根据您希望视图适合的屏幕分辨率进行更改.

now that i have mentioned "dp" here instead of dip android wants me to keep track for different dimensions for different screen resolution, So i will change the image_view_width and image_view_height values are in separate values folders where dimens.xml is located. Make sure your dp values change as per your screen resolution you want your view to fit in.

 <ImageView
        android:id="@+id/avtar_animation_11"
        android:layout_width="@dimen/image_view_width"
        android:layout_height="@dimen/image_view_height"
        android:src="@drawable/avtar011"/>

现在困难的部分已经结束,android 将根据您的应用程序正在运行的屏幕选择一个 dimens.xml 值,瞧,现在您的布局摇摆不定

hard part is over now android will pick one of dimens.xml values depending on which screen your app is running, Voila now your layout rocks

这篇关于不同高度的 Android 设备采用相同的布局文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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