不幸的是,Moto360 还没有在欧洲使用...
我正在运行一个圆形 Android Wear 模拟器,它工作正常。
但是,当我运行我的 Android Wear Activity(使用 WatchViewStub)时,使用的布局是 rect_activy_layout 而不是圆形布局
还有其他人在运行 Round Emulator 时遇到此问题或已解决吗?
谢谢
最佳答案
由于没有正确使用 WatchViewStub 而导致的 inflating layout 有很多问题。我没有看到任何确切知道的代码,但一个常见的问题是当您为 watch insets 注册一个监听器时,您可以检查它在您的 onApplyWindowInsets 处理程序中是圆形还是方形:
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;
}
});
我见过人们忘记返回 windowInsets 或忘记调用 stub.onApplyWindowInsets() 的情况。这具有提供方形布局而不是圆形布局的效果。
此外,SDK 中内置的 AndroidWearRound 模拟器存在错误。它们一共有三个,如果您创建了错误的一个,它实际上会创建一个方形模拟器。如果您有三个模拟器,请确保选择第二个。此错误已在最新的 Android SDK 工具 23.0.4 中修复,但可能是您使用的版本较旧。
您能向我们展示您围绕 WatchViewStub 编写的代码吗?
关于android - 圆形 Android Wear 模拟器使用的是矩形布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25953614/