【问题标题】:Specifying layouts for mobile and wear modules指定移动和穿戴模块的布局
【发布时间】:2016-03-21 15:12:01
【问题描述】:

我从头开始为移动(minSdkVersion 为 9)和 Wear(minSdkVersion 为 20)模块创建了一个新项目,我想知道如何为 wear-round 和 wear-square 指定布局(我需要稍微玩一下 WatchViewStub 类吗?)设备。比如,我知道数据是从手持设备发送到穿戴设备的,但我该如何配置它,以便应用程序在穿戴式圆形和穿戴式正方形布局上运行(特别是仅使用 XML 文件)?

这是我的手机\...\activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Hello mobile world!"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

至于wear 模块下的布局,一切都是默认的(我没有修改任何内容),因此包括但不限于通过实现 WatchViewStub 类的充气机、圆屏和方屏的 XML应该输出“Hello Square World!”和“Hello Round World!”,分别等等。

这是我未动过的衣服\...\MainActivity:

package dpark.gameoflife;

import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.widget.TextView;

public class MainActivity extends Activity {
    private TextView mTextView;

    @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) {
                mTextView = (TextView) stub.findViewById(R.id.text);
            }
        });
    }
}

...然后这是我从 Wear 虚拟模拟器中得到的:

为什么我上面的圆形虚拟模拟器没有出现圆形?

谢谢,非常感谢。

【问题讨论】:

    标签: android android-layout android-studio mobile wear-os


    【解决方案1】:

    资源限定符 layout-roundlayout-square 仅在 SDK 级别 23 中引入。要针对圆形和方形显示具有不同布局的早期级别,您需要使用 WatchViewStubBoxInsetLayout,两者都 @ 987654321@.

    不过,根据您的发布时间表,您也可以只针对可穿戴设备方面的 SDK 23。 23 已经出现在大多数手表上,而且 Google 已经表示所有 Wear 设备都将很快获得它(ish)。

    至于你的圆形模拟器显示方形......没有很好的解释,但他们有时会这样做。重新启动几次,必要时删除并重新创建它,最终它应该会自行解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多