Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Android Wear Emulator is using rect layouts

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

like image 412
Java Guy Avatar asked Sep 20 '14 21:09

Java Guy


1 Answers

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?

like image 166
Wayne Piekarski Avatar answered Oct 15 '22 23:10

Wayne Piekarski