2014-09-25 81 views
0

這是我第一次嘗試使用Android Studio,我已將Eclipse用於以前的應用程序。 我爲Google Wear創建了一個應用程序,我希望包含該功能以根據方形或圓形手錶自動更改佈局。Android Wear自動佈局

而這實際上是默認的代碼,但我無法得到它的工作,也許有人可以指出我在正確的方向。

它總是使用方形佈局,我在實際的圓形手錶(Moto 360)上嘗試過它,並且在Android Studio的佈局窗口中也是如此,即使我選擇了磨損圓形選項,它仍然使用方形佈局。

Activity.java

private TextView mTextView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_wear_activity); 
    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); 
     } 
    }); 
} 

rect_main_wear_activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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" 
android:orientation="vertical" 
tools:context=".MainWearActivity" 
tools:deviceIds="wear_square"> 

<TextView 
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_square" /> 
</LinearLayout> 

round_main_wear_activity.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=".MainWearActivity" 
tools:deviceIds="wear_round"> 

<TextView 
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="@string/hello_round" /> 
</RelativeLayout> 

main_wear_activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.wearable.view.WatchViewStub 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/watch_view_stub" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:rectLayout="@layout/rect_main_wear_activity" 
app:roundLayout="@layout/round_main_wear_activity" 
tools:context=".MainWearActivity" 
tools:deviceIds="wear"> 
</android.support.wearable.view.WatchViewStub> 
+0

我重新啓動了Moto 360,現在它在該設備上工作,在Android Studio中仍然存在同樣的問題,也許它不可能在那裏測試該功能? – 2014-09-26 18:13:59

回答

0

就AndroidWear Round模擬器而言,這顯然是一個錯誤。今天Google發佈了SDK Tools 23.0.4以及一個新的系統映像(rev2),它應該修復您在文章中描述的錯誤。

這是一個被Wayne Piekarski 「官方」 聲明:

Android開發工具團隊剛剛發佈了SDK工具23.0.4。 此版本包含AndroidWearRound仿真器的更新,因此 現在有一個正確的配置文件,而不是以前存在的三個不同的 配置文件。所以去Android SDK Manager和 下載更新SDK Tools 23.0.4,以及Android Wear ARM EABI v7a系統映像修訂版。 2,然後在AVD Manager中重新創建您的AndroidWearRound AVD。

我剛測試過這個,我可以確認這個bug已經解決了。但是仍然無法使用主機GPU。 (問題描述爲here