Android Wear OS Watch Face支持不同的屏幕尺寸 [英] Android Wear OS Watch Face Support different screen sizes

查看:252
本文介绍了Android Wear OS Watch Face支持不同的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Watch Faces for Wear OS上玩耍

I'm playing around Watch Faces for Wear OS

当前,我已经创建

  • 背景320x320
  • 勾选圈320x320
  • 时针,分针和秒针320x40

在屏幕尺寸为320x320的圆形设备上,一切都可以正常工作

Everything works fine on round devices with the screen size 320x320

当我使用屏幕尺寸为360x360的设备时,事情变得越来越复杂.从下面的屏幕快照中可以看到,刻度线"的大小不会自动调整.

Things are getting complicated when I am using devices with screen sizes 360x360. As you can see from the screenshot below the size of Tick Circle is not automatically adjusted.

由于我是开发Watch Faces的新手,而且在官方文档网站上也没有太多相关信息,因此我想了解如何处理这些情况?

As I am new to developing Watch Faces and there is not much information about that on the Official Documentation Website, I want to understand how I should handle these cases?

我应该为每个尺寸创建具有正确尺寸的单独图像,并将其放在正确的文件夹中,例如:

Should I create for each size separate image with the correct size and put it in the correct folder like:

  • drawable-round-320dpi
  • drawable-round-360dpi
  • drawable-round-390dpi

或者还有其他方法可以实现,我宁愿不要从代码中以编程方式调整图像的大小,但是如果这是我可以尝试的唯一解决方案.

Or is there some other way of doing this, I would prefer not to resize images programmatically from the code, but if it is the only solution I can try.

这是我的游乐场项目源代码代码

Here is my playground project source code

P.S.任何文档,源代码都将非常有用.

P.S. Any documentation, source code will be very useful.

推荐答案

在上面的示例中,两个设备都属于hdpi密度桶,但是屏幕尺寸仍然略有不同.您可以使用最小宽度限定符来单独定位它们.但是,这将需要大量额外资源,以确保您覆盖所有可用的屏幕尺寸.

In your example above, both devices fall into the hdpi density bucket, but the screen size still differs slightly. You could target them individually by using the minimum width qualifier. However, this would require a number of extra assets to make sure you cover all available screen sizes.

我个人更喜欢对代码中的资产执行简单的缩放操作.在运行时检查屏幕大小,并将其用作可绘制对象(或位图)的边界.看起来可能像这样:

Personally I prefer to just do a simple scaling operation on the asset in code. Check the screen size at runtime and use that as the bounds for your drawable (or bitmap). It could look something like this:

DisplayMetrics displayMetrics = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
Rect screenBounds = new Rect(0, 0, width, height);

Drawable faceMarkers = context.getDrawable(R.drawable.face_markers);
faceMarkers.setBounds(screenBounds);

faceMarkers.draw(canvas);

确保提供的资产足够大,可以容纳每个密度桶中的最大屏幕.只要您缩减资产一点点,它就不会引起注意.

Make sure that you provide an asset that's large enough for the largest screen in each density bucket. As long as you scale down your asset just a little bit it shouldn't be noticeable.

这篇关于Android Wear OS Watch Face支持不同的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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