3

我正在开发一个 Android Wear 应用程序,屏幕底部的内容由于黑条而被裁剪。

该视频说我们应该像这样获得条形的高度:

@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
   int barHeight = insets.getSystemWindowInsetBottom();
}

但实际上 barHeight 始终为 0。

现在我正在破解它

if (Build.MODEL.equals("Moto 360")) {

}

但这不是很面向未来。有什么提示吗?

4

1 回答 1

1

I use the window insets to determine the "chin" height in an Activity of a Wear app and in a watch face engine, so it does work. I've tested on a Moto 360. This is an extract from an Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
            stub.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                    int chinHeight = insets.getSystemWindowInsetBottom();
                    // chinHeight = 30;
                    return insets;
                }
            });
        }
    });
}
于 2015-02-01T18:22:00.863 回答