0

I am using LinearLayout inside BoxInsetLayout and required to have gravity center for round face & left for square face.

It's possible with WatchViewStub but i have to use BoxInsetLayout.

so is there way we can apply 2 different styles for each faces?

Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • 1
    Perhaps you are better off making 2 layouts in qualified directories (e.g. `layout-round` or `layout-notround`). The common content can be ``ed in both. – Karakuri Jan 12 '17 at 06:30
  • @Karakuri this both layout added in API 23. is there a way to do for lower version? – Sanket Kachhela Jan 12 '17 at 09:29
  • You might want to check the documentation about [Creating Watch Faces](https://developer.android.com/training/wearables/watch-faces/index.html), it stated Android 4.3 (API level 18) or higher on the handheld device and Android 5.0 (API level 21) or higher on the wearable device. Hope this helps. – Mr.Rebot Jan 12 '17 at 14:40
  • @Mr.Rebot those 2 directories is only working with API 23 or greater.. so is there any way so we can apply 2 different styles for round & rect view inside boxinsetLayout? – Sanket Kachhela Jan 12 '17 at 17:34

1 Answers1

0

You can check at runtime if the screen is round using the following:

private class Engine extends CanvasWatchFaceService.Engine {
    boolean mIsRound;

    @Override
    public void onApplyWindowInsets(WindowInsets insets) {
        super.onApplyWindowInsets(insets);
        mIsRound = insets.isRound();
    }
    ...
}

This is described in the Creating Watch Faces developer guide. WindowInsets.isRound() was added in API 20, so this should be available to you. Based on this value you can set the appropriate gravity for your content.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • yeah it's way.. but i think it will increase more time complexity if we have more views. so it would be better if google provides such solution in support library. – Sanket Kachhela Jan 13 '17 at 06:05
  • i have added feature request https://code.google.com/p/android/issues/detail?id=232122&thanks=232122&ts=1484288818 . can you please take follow up as you are working at google :) – Sanket Kachhela Jan 13 '17 at 06:28
  • @SanketKachhela There's really no way to backport configuration qualifiers for resources, so I doubt there would be anything added to the support library. – Karakuri Jan 13 '17 at 15:38