简体   繁体   English

多个设备的后台/ UI

[英]Background/UI for multiple devices

I'm new to Android programming and I'm stuck with a very specific problem. 我是Android编程的新手,但我遇到了一个非常具体的问题。 I want my application to run on multiple screen sizes and densities. 我希望我的应用程序可以在多种屏幕尺寸和密度下运行。

I have several real devices with different screen resolutions (Samsung Galaxy S7 Edge [xxxhdpi], Samsung Galaxy A5(6) [xxhdpi], Samsung Galaxy Note 10.1 tablet [xhdpi]. 我有几种具有不同屏幕分辨率的真实设备(三星Galaxy S7 Edge [xxxhdpi],三星Galaxy A5(6)[xxhdpi],三星Galaxy Note 10.1平板电脑[xhdpi]。

I made one background and scaled it down for every generalized density. 我制作了一个背景,并针对每种通用密度将其按比例缩小。 I saved the files as “background.png” in separate folders like suggested in Supporting Multiple Screens . 我将文件另存为“ background.png”,位于“ 支持多屏幕 ”中建议的单独文件夹中。

After testing the APK on the devices, everything worked fine except the background on the S7. 在设备上测试APK之后,除S7的背景外,其他所有功能均正常运行。 It will always load the next lower resolution bitmap (xxhdpi instead of xxxhdpi). 它将始终加载下一个较低分辨率的位图(xxhdpi而不是xxxhdpi)。 I looked countless threads how to fix this problem but nothing worked so far. 我看着无数线程如何解决此问题,但到目前为止没有任何效果。

The resolutions of my bitmaps are: 我的位图的分辨率是:

drawable-mdpi        //320x480
drawable-hdpi        //480x800
drawable-xhdpi       //720x1280
drawable-xxhdpi      //1080X1920
drawable-xxxhdpi     //1440X2560

I hope that someone can help me on this one. 我希望有人可以帮助我。 I'm really losing my mind. 我真的迷失了方向。

This is a little complex but I'll try to keep it simple. 这有点复杂,但我会尽量简化。 The android system chooses the right resources based on a lot of factors (which you can see when you create a new resource file under the "Available qualifiers" list) which you can group to create a resource shared by different configurations or use only one of them to specify one particular configuration. android系统会根据多种因素(在“可用的限定词”列表下创建新资源文件时会看到这些因素)选择合适的资源,您可以将其分组以创建由不同配置共享的资源或仅使用以下一种它们指定一种特定的配置。 But you cannot control witch resource the device will use for the most part (there are some you can specify yourself ex: night mode). 但是您无法控制设备将大部分使用的资源(有些功能可以自己指定:夜间模式)。 Your S7 probably uses the wrong resource because probably one of the settings for the display resolution is set at a lower setting (ex: battery saving modes lower resolution, gaming mode.. etc, accessibility settings). 您的S7可能使用了错误的资源,因为显示分辨率的设置之一可能设置为较低的设置(例如:省电模式,分辨率较低,游戏模式等可访问性设置)。 And if you want a tablet to use a different drawable then a phone then you should use the "smallest screen width" qualifier since you can specify different screen sizes in Dip(ex: sw320dp is a normal phone, sw440dp is a big pixel phone, sw720dp is a medium tablet and sw1048dp is a bigger tablet). 如果您希望平板电脑使用其他可绘制对象而不是手机,则应使用“最小屏幕宽度”限定符,因为您可以在Dip中指定不同的屏幕尺寸(例如: sw320dp是普通电话, sw440dp是大像素电话, sw720dp是中型平板电脑,而sw1048dp是较大的平板电脑)。 Read more here 在这里阅读更多

I'm also facing like this. 我也面对这样。 My app only works on high resolution mobile only. 我的应用仅在高分辨率移动设备上有效。 Then I found that error. 然后我发现了这个错误。 I placed my drawable on drawable-hdpi only . 我只将drawable放在drawable-hdpi上。 For every assets we have to place default drawable in drawable folder 对于每个资产,我们都必须将默认可绘制对象放置在可绘制文件夹中

put default drawable in that folder. 将默认可绘制对象放入该文件夹。 drawable

For handling images on the s7 device we can give height and width to the image view. 为了在s7设备上处理图像,我们可以为图像视图指定高度和宽度。 Set the values for height and width from the dimens file. 从dimens文件中设置高度和宽度的值。 For handling s7 UI need to add the dimens-sw411 file and specify the height and width in that. 为了处理s7 UI,需要添加dimens-sw411文件并在其中指定高度和宽度。

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

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