2016-03-21 25 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