【问题标题】:How to detect height of black bar on Moto 360?如何检测 Moto 360 上黑条的高度?
【发布时间】:2025-09-24 14:15:02
【问题描述】:

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

This video 说我们应该像这样得到条的高度:

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

但实际上 barHeight 始终为 0。

现在我正在破解它

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

}

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

【问题讨论】:

    标签: wear-os moto-360


    【解决方案1】:

    我使用窗口插图来确定 Wear 应用程序的 Activity 和表盘引擎中的“下巴”高度,所以它确实有效。我在 Moto 360 上进行了测试。这是一个活动的摘录:

    @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;
                    }
                });
            }
        });
    }
    

    【讨论】:

    • 哦,我明白了,看来你需要在 onLayoutInflated 方法中设置监听器,我是在 GridViewPager 实例上调用的。
    最近更新 更多