Round Android Wear Emulator is using rect layouts

早过忘川 提交于 2019-12-07 02:41:15

问题


Unfortunately Moto360 is not avail to Europe yet...

I'm running a Round Android Wear Emulator and this is working fine.

However when I run my Android Wear Activity (which uses a WatchViewStub) the layout being used is the rect_activy_layout and not the round layout

Anyone else have this issue or resolved when running Round Emulator?

Thanks


回答1:


There are many problems with inflating layouts that are caused by not correctly using WatchViewStub. I don't see any code to know exactly, but one common issue is when you register a listener for watch insets so you can check if it is round or square inside your onApplyWindowInsets handler:

    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
            // Need to also call the original insets since we have overridden the original                                                  
            // https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener.html                                   
            stub.onApplyWindowInsets(windowInsets);

            // this is where you would check the WindowInsets for isRound()

            return windowInsets;
        }
    });

I see cases where people forget to return the windowInsets, or forget to call stub.onApplyWindowInsets(). This has the effect of giving a square layout instead of a round layout.

Also, there was a bug with the AndroidWearRound emulator built into the SDK. There were three of them, and if you created the wrong one, it would actually create a square emulator. Make sure if you have three emulators, that you pick the second one. This bug has been fixed in the latest Android SDK Tools 23.0.4, but it might be that you have an older version.

Can you show us the code you are doing around the WatchViewStub?




回答2:


One easy fix is to upgrade the Wear Round emulator to API level 22, which is out now. I have in general found the Wear Round emulator at API level 21 to have some buggy behaviour, while so far have not found any problems with the Round emulator at API level 22. I think this will fix the issue, as I had the same problem myself at some point (and it was NOT a setup problem of the emulator).



来源:https://stackoverflow.com/questions/25953614/round-android-wear-emulator-is-using-rect-layouts

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