【发布时间】: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