我很想知道磨損類型,無論是圓形還是方形,因爲根據設備類型我想爲圓形和方形制作不同的視圖。從This Post我知道在SDK-20 android.view.View
類有一個新的偵聽器來檢測設備類型,使用此我試圖獲取設備類型,但沒有打印logcat上。以下是我試過的代碼。Android Wear類型檢測 - 圓形或方形
public class WearSplash extends Activity implements OnApplyWindowInsetsListener {
private WatchViewStub _stub = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear_splash);
_stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
_stub.setOnApplyWindowInsetsListener(this);
_stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub mStub) {
// here on the basis of device type i want to inflate views.
}
});
}
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
System.out.println(" in testing phase");
if (insets.isRound())
System.out.println("in round");
else
System.out.println("in square");
return null;
}
}
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"
app:roundLayout="@layout/round"
tools:context="com.app.WearSplash"
tools:deviceIds="wear" >
</android.support.wearable.view.WatchViewStub>
回合:
<?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="com.app.WearSplash"
tools:deviceIds="wear_round" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/hello_world" />
</RelativeLayout>
廣場:
<?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="com.app.WearSplash"
tools:deviceIds="wear_square" >
<ImageView
android:id="@+id/image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:contentDescription="@string/hello_world"
android:background="@drawable/ic_launcher"/>
</LinearLayout>
我是新穿的發展,讓我知道我錯了。幫助雙手將受到高度讚賞。
不知道它是這樣的問題,我還沒有試過穿要麼,但是當我試圖執行'OnApplyWindowInsetsListener'在Android Studio中,它被認爲是自動完成的'View.OnApplyWindowInsetsListener'。所以你可以試試'公共類WearSplash擴展活動實現View.OnApplyWindowInsetsListener'而不是'類WearSplash擴展活動實現OnApplyWindowInsetsListener'。 –
已經嘗試過,不能正常工作 – Dev
實際上,當我試圖在沒有View.'部分的情況下實現'OnApplyWindowInsetsListener'時,出現錯誤。 –