這是我第一次嘗試使用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>
我重新啓動了Moto 360,現在它在該設備上工作,在Android Studio中仍然存在同樣的問題,也許它不可能在那裏測試該功能? – 2014-09-26 18:13:59