Android Wear OS Watch Face Support different screen sizes

前端 未结 1 1625
臣服心动
臣服心动 2021-01-28 09:21

I\'m playing around Watch Faces for Wear OS

Currently, I have created

  • Background 320x320
  • Tick Circle 320x320
  • Hours, Minutes and Seconds Han
相关标签:
1条回答
  • 2021-01-28 10:02

    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.

    0 讨论(0)
提交回复
热议问题