Android 通用应用程序要求
我想开发一个可以在所有屏幕类型的Android手机上运行的Android应用程序。所以我的问题是:
将所有图像资源仅保留在 HDPI 文件夹中可以吗?或者我需要所有 3 种类型的资源 LDPI 、 MDPI 和 HDPI 吗?
如果我使用相对布局来开发这个应用程序,那么上面有一些文本的图像会发生什么(_按钮背景图像将有一些文本“提交”)。 Android 会根据设备屏幕缩放图像,但它是否也能够相应地缩放文本?
请建议我如何处理这个问题。
如何制作一个可以在所有类型屏幕的Android手机上运行的应用程序?
I want to develop an Android application which can run on all ,screen type ,Android phones. So my question is:
Would it be okay to to keep all image resources in HDPI folder only? Or will I need all 3 type of resources LDPI , MDPI AND HDPI?
If I use relative layout for developing this app so what would happen for the images which have some text on it ( _ button background image which will have some text "Submit" ). Android will scale the image according to device screen but is it capable to scale text also accordingly?
Please suggest me how to deal with this problem.
How to make an app which can work on all type screen Android phones?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要开发支持多屏幕的 Android 应用程序,您必须简要阅读本教程:Android 多屏幕屏幕支持
您的问题要点:
1.drawable 中的特定资源会根据密度自动获取。
因此,您应该将特定图像相应地放置在 mdpi、hdpi、ldpi 中。
2.阅读并理解清单支持屏幕标记值:
3.应调整文本大小:
您应该使用样式,然后您可以拥有单独的文件夹“values”(默认)“values-hdpi”(高密度)“values-mdpi” (中等密度)等等,并根据需要将具有正确 textSize 值的样式文件放入每个文件夹中。
然后,当您使用中密度设备时,如果存在,它将选择“values-mdpi”文件夹中的文件,如果不存在,则选择“values”文件夹中的文件,对于高密度设备也是如此......
同样的原则适用于所有“res”子文件夹(可绘制对象、值等...)
或者简单地,如果不选择样式,只需使用
dp
而不是sp
作为文本尺寸。To develop a android application that has mutiple screen support you must go through this tutorial in brief:Android Mutiple Screen Support
In gist of your questions:
1.The specific asset in drawable are automatically taken depending on density.
So you should place specific images in mdpi,hdpi,ldpi accordingly.
2.Read and understand manifest support screen tag values:
3.The Text should be resized:
You should use styles, then you can have separate folders "values" (default) "values-hdpi" (high density) "values-mdpi" (medium density) and so on and put your style file with correct textSize values in each folder as needed.
Then, when you are in medium density device it will pick the file in "values-mdpi" folder if exists or in "values" if not, and the same for high density etc...
This same principle applies to al "res" subfolders (drawables, values, etc...)
Or Simply If do not go for styles just use
dp
instead ofsp
for text dimension.如果您仅将图像放入 HDPI 文件夹中,它就可以工作。但理想情况下,您应该根据密度放置图像。另外,如果您在按钮背景上使用 9 个补丁图像,Android 会根据要求拉伸图像,但是如果在某些情况下您发现图像未正确拉伸,您可以为横向和纵向模式使用单独的图像。
If you put images in HDPI folder only, it will work. but ideally you should put images according to density. also if you use 9 patches image on button background, android stretches the images according to requirement however if in some case you find that image are not properly stretching you can use separate images for landscape and portrait mode.
如果我使用相对布局来开发此应用程序,那么带有一些文本的图像会发生什么(例如,带有一些文本“提交”的按钮背景图像)。 android 会根据设备屏幕缩放图像,但它是否也能够相应地缩放文本?
=>如果您想提供可根据屏幕尺寸自动收缩/拉伸的可缩放图像,那么有一个9-patch工具,您可以通过它创建可缩放图像,之后您就不需要需要担心屏幕尺寸和屏幕密度。
这是一个很好的例子: http://www.dibbus.com/ 2011/03/9patch-images-in-android/
这里还有一篇不错的文章和创建 9-patch 图像的指南:http://radleymarx.com/blog/simple-guide-to-9-patch/
If I use relative layout for developing this app so what would happen for the images which have some text on it ( e.g a button background image which will have some text "Submit" ) . android will scale the image according to device screen but is it capable to scale text also accordingly?
=> If you want to provide scalable images which can be shrinked/stretched automatically as per the screen size, then there is a 9-patch tool by which you can create a scalable image and after that you don't need to worry about the screen size and screen density.
Here is a nice example: http://www.dibbus.com/2011/03/9patch-images-in-android/
Here is also a nice article and guide to create 9-patch image: http://radleymarx.com/blog/simple-guide-to-9-patch/