2016-03-21 57 views
0

我为移动设备(minSdkVersion为9)和磨损(minSdkVersion为20)模块创建了一个新项目,我在想如何指定磨损轮廓和磨损的布局-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> 

至于磨损模块,一切都默认下的布局(我没有做任何修改),从而使包括,但不仅限于通过实施WatchViewStub类的充气器,用于圆形和方形屏幕的XML,它们应输出“Hello Square 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); 
      } 
     }); 
    } 
} 

...然后这就是我从穿虚拟仿真得到:

enter image description here

为什么我的一轮虚拟模拟器上面不会出现圆的?

enter image description here

谢谢,我非常感激。

回答

1

资源预选赛layout-roundlayout-square在SDK级别23只引入target具有为圆形和方形显示不同的布局同期的水平,你会希望用WatchViewStubBoxInsetLayout,既documented here

不过,根据您的发布计划,您也可以在可穿戴侧瞄准SDK 23。 23已经在大多数手表上了,Google已经表示所有Wear设备都会很快得到它(ish)。

至于你的圆形模拟器显示广场...有没有很好的解释,但他们只是有时做到这一点。重新启动它几次,删除并重新创建它,如果必须的话,最终它应该自行排除。

+0

谢谢先生! :) – DaveNOTDavid