如何在 list 中将平板电脑的方向设置为手机的横向和纵向?
我要:
<application
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:installLocation="preferExternal"
android:label="@string/app_name"
android:largeHeap="true"
<!--for phones-->
android:screenOrientation="portrait"
<!--for tablets-->
android:screenOrientation="landscape"
....
在一份 list 中。可能吗?
最佳答案
不,这是不可能的,你必须在运行时检查。
检查它是否是平板电脑:
public static boolean isTablet(Context context)
{
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
然后在您的 Activity 中,在 setContentView()
之前像这样设置方向if(isTablet(this))
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
else
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
关于android - 如何在 list 中将平板电脑的方向设置为手机的横向和纵向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762004/