Android Wear OS Watch Face Support different screen sizes

最后都变了- 提交于 2019-12-02 12:53:55

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!