我的Xml设计在所有Android设备中都不工作? [英] My Xml design not working in all android Devices?

查看:120
本文介绍了我的Xml设计在所有Android设备中都不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我的设计在我的Android HTC 2.3.4中正常工作但在4.0.1我的屏幕没有显示完整(一些设计是从底部切割)。为什么?

解决方案

由于您尚未发布任何代码,我将简要介绍一下Android布局和资源



您必须为您的应用创建多个资源。 Android有4种分辨率(ldpi,mdpi,hdpi和xhdpi)和4种广泛的屏幕尺寸(小,中,大和特大)。因此,您必须制作4个布局(如果您不打算支持平板电脑,则为3,因为平板电脑属于超大类别)以支持屏幕尺寸。



以下是一般的指南:



在您的res /文件夹中放置小,中,大和超大的布局,如下所示:

  res / layout / sample_layout.xml //默认布局
res / layout-small / sample_layout.xml //小屏幕尺寸的布局
res / layout-large / sample_layout.xml //大屏幕尺寸的布局
res / layout-xlarge / sample_layout.xml //超大屏幕尺寸的布局

您还可以使用



res / layout-land / sample_layout.xml 用于所有屏幕尺寸的横向,或者您可以将特定屏幕尺寸的景观布局定位为 res / layout-medium-land / sample_layout.xml



请注意,所有的布局都有相同的名称。



一次您的布局准备就绪,您还需要照顾图像分辨率,再次在您的res /文件夹中添加图像:

  res / drawable-ldpi / sample_image.png // low density 
res / drawable-mdpi / sample_image.png // medium density
res / drawable-hdpi / sample_image.png //高密度
res / drawable-xhdpi / sample_image.png // extra high density

再次,所有的图像都具有相同的名称。



设计图像的一般准则是:

  ldpi是0.75x尺寸的mdpi 
hdpi是mxpi的1.5x尺寸
xhdpi是mdpi的二维尺寸

一般来说,我为320x480屏幕设计mdpi图像,然后根据上述规则乘以尺寸以获取其他分辨率的图像。



Android将自动选择布局和图片的最佳组合,具体取决于e设备。例如,对于高分辨率中等尺寸的设备,布局介质和高密度图像将显示给用户。



确保为所有这些组合创建仿真器,彻底测试你的应用程序以下是官方文档的更多信息:



https://developer.android.com/guide/practices/screens_support.html


In my project, My Design is working fine in my android HTC 2.3.4 But on 4.0.1 my screen is not showing full ( Some design is cutting from Bottom). Why?

解决方案

Since you haven't posted any code, I'll just give you a brief overview of android layouts and resources.

You have to create multiple resources for your app. Android has 4 resolutions (ldpi,mdpi,hdpi and xhdpi) and 4 generalized screen sizes (small, medium, large and extra large). So you have to make 4 layouts (or 3 if you don't plan on supporting tablets, since tablets come under the extra large category) to support the screen sizes.

Here's a general guide:

put layouts for small, medium, large and extra large in your res/ folder as follows:

res/layout/sample_layout.xml             // default layout
res/layout-small/sample_layout.xml       // layout for small screen size
res/layout-large/sample_layout.xml       // layout for large screen size
res/layout-xlarge/sample_layout.xml      // layout for extra large screen size

you can also use

res/layout-land/sample_layout.xml for landscape orientation for all screen sizes or you can target landscape layouts for specific screen sizes as res/layout-medium-land/sample_layout.xml

note that all the layouts have the same name.

once you have your layouts ready, you need to take care of image resolutions also

once again in your res/ folder add images like this:

res/drawable-ldpi/sample_image.png         // low density
res/drawable-mdpi/sample_image.png         // medium density
res/drawable-hdpi/sample_image.png         // high density
res/drawable-xhdpi/sample_image.png        // extra high density

once again, all the images have the same name.

general guidelines for designing images are:

ldpi is 0.75x dimensions of mdpi
hdpi is 1.5x dimensions of mdpi
xhdpi is 2x dimensinons of mdpi

generally, I design mdpi images for a 320x480 screen and then multiply the dimensions as per the above rules to get images for other resolutions.

Android will automatically select the best combination of layout and image depending on the device. For example, for a high resolution medium size device, layout-medium and high density image will be displayed to the user.

Make sure you create emulators for all these combinations and test your app thoroughly. here's the official docs for more info:

https://developer.android.com/guide/practices/screens_support.html

这篇关于我的Xml设计在所有Android设备中都不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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