gpt4 book ai didi

Android Wear类型检测——圆形或方形

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:56 25 4
gpt4 key购买 nike

我很好奇佩戴类型,是圆形还是方形,因为我想根据设备类型对圆形和方形做出不同的看法。来自 This Post我知道在 SDK-20 中 android.view.View 类有一个新的监听器来检测设备类型,使用它我试图获取设备类型但 logcat 上没有打印任何内容。下面是我试过的代码。

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>

我是 wear 开发的新手,让我知道我哪里出错了。我们将不胜感激。

最佳答案

引入了 API 23:

isScreenRound()

关于Android Wear类型检测——圆形或方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24907557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com