手机纵向,平板横向(Android-布局) [英] Portrait for phone, landscape for Tablet (Android-Layout)

查看:27
本文介绍了手机纵向,平板横向(Android-布局)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在为 Android 制作一个应用程序,我想强制平板电脑横向和手机纵向.但是,似乎我只能根据我所看到的情况进行方向锁定,这违背了为设备提供两个单独方向的目的.

So I'm making an application for Android and I want to force Landscape orientation for tablets and Portrait orientation for phones. However, it seems as though I can only do an orientation lock from what I've seen which defeats the purpose of wanting two separate orientations for devices.

平板电脑:横向手机:纵向

Tablets: Landscape Phones: Portrait

说得更有技术含量.

我在res/layout-xlarge-land"中有一个布局用于在平板电脑上进行景观美化,而我在res/layout"中有原始布局,我只想明确地为平板电脑使用 layout-xlarge-land.没有别的,基本上只对 xlarge 设备使用横向.

I have a layout in "res/layout-xlarge-land" for landscaping on the tablet and I have the original layout in "res/layout" and I just want to explicitly use layout-xlarge-land for the tablet. Nothing else, essentially ONLY using landscape for xlarge devices.

谢谢!

推荐答案

根据设备密度设置特定方向可能不起作用,因为有些手机的密度高于平板电脑.

Setting a particular orientation based on device density may not work because there are phones which have higher densities than tablets.

我所做的是通过在清单文件的活动标签中设置属性来禁用设备的方向传感器,如下所示:

What I did was to disable the device's orientation sensor by setting the attribute in the activity tag in the manifest file like this:

android:screenOrientation="nosensor"

当您运行您的应用时,默认情况下,手机设置为纵向,平板电脑设置为横向(因此它将从 layout-xlarge-land 中选择 xml 文件).并且由于您设置了方向锁定,因此它保持在该方向.

When you run your app, by default portrait orientation is set for phones and landscape for tablets(and hence it'll select the xml file from layout-xlarge-land). And since you've set an orientation lock, it remains in this orientation.

这篇关于手机纵向,平板横向(Android-布局)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆