为什么我的可穿戴设备无法识别正方形或圆形的形状,结果在我的代码中只是方形?我的可穿戴设备是moto 360。
以下代码位于onCreate():
setContentView(R.layout.main_activity);
WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
String shapeDetect = "";
View rect = findViewById(R.id.main_page_rect_layout);
if (rect != null) {
shapeDetect = ((TextView)rect.findViewById(R.id.rect_shape_detect)).getText().toString();
}
View round = findViewById(R.id.main_page_round_layout);
if (round != null) {
shapeDetect = ((TextView)round.findViewById(R.id.round_shape_detect)).getText().toString();
}
System.out.println("shape-->" + shapeDetect);
}
});
main_activity,XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.wearable.view.WatchViewStub
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/stub"
app:rectLayout="@layout/main_page_rect_layout"
app:roundLayout="@layout/main_page_round_layout"/>
</FrameLayout>
main_page_rect_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_page_rect_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="@+id/rect_shape_detect"
android:text="rect"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
main_page_round_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_page_round_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="@+id/round_shape_detect"
android:text="round"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
无论如何,代码打印结果是'shape - &gt; rect'