Android Wear type detection - Round Or Square

前端 未结 4 1725
悲&欢浪女
悲&欢浪女 2020-12-30 06:56

I am curious to know about the wear type, whether it\'s round or square, because on the basis of device type I want to make different views for round and square. From This

相关标签:
4条回答
  • 2020-12-30 07:06

    Unofficial way (without using WatchViewStub) - but for me it was way way easier. https://github.com/tajchert/ShapeWear

    Just copy ShapeWear.java class, and subscribe to screen shape detection event setOnShapeChangeListener() or call method ShapeWear.isRound() (can throw error is shape is not yet determined) or ShapeWear. getShape() - which can result in ShapeWear.SHAPE_UNSURE in same situation.

    0 讨论(0)
  • 2020-12-30 07:11

    Use WatchViewStub to inflate the view.Later in the layout file you may specify the layout for each watch type as below.It will automatically pick the correct layout as required by the device.

    <android.support.wearable.view.WatchViewStub
        .
        .
        .
        app:rectLayout="@layout/rect_activity_my_wear"
        app:roundLayout="@layout/round_activity_my_wear"
        .
        .
        .
    >
    
    0 讨论(0)
  • 2020-12-30 07:20

    If you need to get this information programmatically, you are correct in adding add a listener for setOnApplyWindowInsetsListener(). However, in order to trigger that, you must also call requestApplyInsets().

    In any case, if you only want to know this to switch between two alternative layouts, you can use the WatchViewStub class which does this automatically (docs here).

    0 讨论(0)
  • 2020-12-30 07:22

    API 23 introduced:

    isScreenRound()

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