我专注于让我的应用在任何设备上工作(具有不同的屏幕尺寸)。 我的第一个问题:我应该为每个资源制作多个 - (前缀)dpi吗?或者建议它为设备指定精确的分辨率? (例如w720dp)有什么区别?第一个解决方案是否适用于所有相同密度的屏幕尺寸? 第二个问题:我应该创建许多资源文件来支持不同类型的屏幕,还是有一种更简单的方法? (例如,为不同的设备定义android:toYDelta属性)
答案 0 :(得分:1)
It's recommended to make resources for different resolution. Best way to do it is to add Image Asset with Image Asset Studio. It will create images for different resolutions (dpi) from one source image. Additionally, app will pick suitable resolution of mipmap for device dpi, so you don't need to worry about images resolution anymore.
You should test your app on few different devices with different dpi, because it may look not quite well, especially on low dpi device. But thanks to dpi, it makes much simpler to test it.
Image Asset Studio example output - I can't upload images yet, that's why I give link to image.
But there's one problem with mipmaps and Asset Studio. It will force to use images with 1:1 aspect ratio. But you can generate mipmaps and then replace them in directories for yours custom images with different aspect ratio and it will work just fine.
Here you can read more about mipmaps:
答案 1 :(得分:1)
It is not possible to test your app on every combined situations: screen size, resolution, version of os, version of sdk and...
Drawables: if possible, use vector drawables, otherwise provide drawables for screen resolutions: mdpi
, hdpi
, xhdpi
, xxhdpi
and xxxhdpi
.
Layouts: If you want to support mobiles and tablets, use Fragment
s and layout
and layout-large
folders.
Orientation: use lyout-port
and layout-land
if you want to support different layouts for land or port orientation.
答案 2 :(得分:0)
你应该使用dpi。当涉及到测试设计或布局时,请使用仿真器。在Android中,工作室模拟器可用于每种屏幕尺寸和每种类型的设备。