android - 如何在 list 中将平板电脑的方向设置为手机的横向和纵向?

标签 android

如何在 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/

相关文章:

没有 XML 的 Android View 对齐底部(以编程方式)

java - 已停止申请! GOOGLE API V2 - map

android - 自定义 ListView 内的可点击 TextView

android - 需要通过 Facebook 和 Twitter 验证用户(PhonegapAndroid)

android - 如何从工具栏中删除应用程序标题?

android - 为什么我的主要 Activity 在从另一个 Activity 返回时黑屏/隐藏?

android - 不能在 Kotlin 中使用 argb color int 值?

android - TextView + 网页 View

java - 在不连接的情况下获取 WiFi 的 SSID?

android - 当我使用 TabLayout 时,我的 Android Studio 的应用程序崩溃了,我该如何解决?