简体   繁体   English

针对不同屏幕尺寸的 Android 设计

[英]Design for Different Screen Sizes Android

I am developing an android app but problem is, it's design doesn't remain consistent on different devices.我正在开发一个 android 应用程序,但问题是,它的设计在不同的设备上并不一致。

I studied about it on internet but finally I am stuck on the same problem.我在互联网上研究了它,但最后我被困在了同样的问题上。

I designed the app in Photoshop by taking the layout design of 720 X 1280 for hdpi and then also modifying it for ldpi, mdpi and hdpi.我在 Photoshop 中设计了该应用程序,采用了720 X 1280的 hdpi 布局设计,然后还针对 ldpi、mdpi 和 hdpi 对其进行了修改。

I developed different layouts for different devices, different folders are:我为不同的设备开发了不同的布局,不同的文件夹是:

layout
layout-small
layout-large
layout-xlarge

They look great on Eclipse but when i run it on real device, buttons are small [on Tablets], works fine on my phone 320 X 480, but I am not sure about other devices.它们在 Eclipse 上看起来很棒,但是当我在真实设备上运行它时,按钮很小 [在平板电脑上],在我的手机 320 X 480 上工作正常,但我不确定其他设备。

I actually mentioned the size of my buttons in dp in the layouts like:我实际上在布局中提到了 dp 中按钮的大小,例如:

layout:
android:layout_width="230dp"
android:layout_height="90dp"

layout-large 
android:layout_width="350dp"
android:layout_height="125dp"

as they looked good in eclipse.因为它们在日食中看起来不错。

For Android launcher icons you will need 6 sizes of PNG or JPG files.对于 Android 启动器图标,您需要 6 种大小的 PNG 或 JPG 文件。 In pixels these are:以像素为单位,这些是:

48×48, 72×72, 96×96, 144×144, 192×192 and 512×512 48×48、72×72、96×96、144×144、192×192和512×512

The first five are for the App and the last one for when the App is deployed to the Google Play store.前五个用于应用程序,最后一个用于将应用程序部署到 Google Play 商店时。

The number of dots (pixels) per inch that an Android device's screen holds determines how sharp the image on the screen looks. Android 设备屏幕上每英寸的点数(像素)决定了屏幕上图像的清晰度。 The more Dots Per Inch (DPI) the sharper the image.每英寸点数 (DPI) 越多,图像越清晰。 Android groups screen densities into several classes, medium, high, extra high, extra extra high and extra extra extra high! Android 将屏幕密度分为几个等级,中、高、超高、超高和超高! These are referred to as MDPI, HDPI, XHDPI, XXHDPI and XXXHDPI.这些被称为 MDPI、HDPI、XHDPI、XXHDPI 和 XXXHDPI。 There is also a low density class, LDPI, however not many new devices have a low density screen and thus LDPI is no longer important.还有一个低密度等级,即 LDPI,但是没有多少新设备具有低密度屏幕,因此 LDPI 不再重要。

MDPI is around 160 DPI MDPI 约为 160 DPI

HDPI around 240 DPI HDPI 大约 240 DPI

XHDPI around 320 DPI XHDPI 大约 320 DPI

XXHDPI around 480 DPI XXHDPI 大约 480 DPI

XXXHDPI around 640 DPI. XXXHDPI 大约 640 DPI。

(LDPI is around 120 DPI). (LDPI 约为 120 DPI)。

It is the screen density that determines the Android icon size used.屏幕密度决定了所使用的 Android 图标大小。

Android Icon Size Table Android 图标大小表在此处输入图片说明

Though people usually have panic on this subject, it's not as difficult as it seems.尽管人们通常对这个问题感到恐慌,但这并不像看起来那么困难。 The main patterns to follow are:要遵循的主要模式是:

  • Try to hardcode the least sizes as you can.尽量硬编码最小的尺寸。 Try avoiding, for instance, 271dp -like codes.例如,尝试避免271dp的代码。
  • Don't use pixels, use density-independent units.不要使用像素,使用与密度无关的单位。 That means: dp for layouts and sp for text sizes.这意味着: dp表示布局, sp表示文本大小。
  • As layout weights and widths, try using match_parent , wrap_content and if you need to do something proportionally, use layout_weight .作为布局权重和宽度,请尝试使用match_parentwrap_content ,如果您需要按比例执行某些操作,请使用layout_weight This latter saves lifes.后者可以挽救生命。

Since you don't provide some specific code, it's hard to give a better advice, but as I see that you're using hardcoded sizes, a good beggining would be addapt it to those patterns.由于您没有提供一些特定的代码,因此很难给出更好的建议,但正如我所看到的,您使用的是硬编码大小,因此最好将其添加到这些模式中。

I strongly recommend reading this reference as it explains exactly what you should do.我强烈建议阅读此参考资料,因为它准确地解释了您应该做什么。

There is no need to create different layout for different screen resolutions.. Just put your images in folder named :无需为不同的屏幕分辨率创建不同的布局.. 只需将您的图像放在名为 的文件夹中:

for resolution - 320*480
=========================================
Folder Name : drawable - mdpi

for resolution - 480*800
=========================================
Folder Name : drawable-hdpi

for resolution - 540*960
=========================================
Folder Name : drawable-sw360dp-hdpi

for resolution - 720*1280
=========================================
Folder Name : drawable-sw360dp-xhdpi

for resolution - 768*1280
=========================================
Folder Name : drawable-sw360dp-notlong-hdpi

When you create design in Photoshop please develop design for XHDPI.当您在 Photoshop 中创建设计时,请为 XHDPI 开发设计。 For make image resources you can use special plugins for create drawable resources in Adobe Photoshop as like http://www.cutandslice.me/ This plugin in automatic create assets for all resolution对于制作图像资源,您可以使用特殊插件在 Adob​​e Photoshop 中创建可绘制资源,例如http://www.cutandslice.me/此插件自动创建所有分辨率的资产

if you use icon for background then generate icon from this link icon generator如果您使用图标作为背景,则从此链接图标生成器生成图标

or if you use simple xml design view then create shap file for all screens with different size of view或者,如果您使用简单的 xml 设计视图,则为具有不同视图大小的所有屏幕创建 shap 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM