我有一个活动A,它有两个类型的布局。手机有单一的布局,平板电脑有主细节布局。主细节布局为7英寸景观和10英寸平板电脑.我使用了以下布局限定符:
-layout - for phones
-layout-sw720dp - for 10 inch tablet
-layout-w820dp-land - for 7 inch tablet landscape
-layout-h820dp - for 7 inch tablet portrait直到现在一切都很好。
问题:
现在,我希望活动只在手机的纵向模式下工作,并在7英寸和10英寸平板电脑的方向上工作,为此,我使用了来自此链接https://stackoverflow.com/a/14793611/373889的以下资源和大小限定符
for res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">true</bool>
</resources>
for res/values-sw720dp
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">false</bool>
</resources>
for res/values-w820dp-land
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">false</bool>
</resources>
for res/values-h820dp
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="portrait_only">false</bool>
</resources>现在的问题是,在7英寸平板电脑中,如果以纵向模式启动,则在两个方向显示正常的手机布局,如果以横向模式启动,则在两个方向上显示主细节布局。它不起作用,它应该起作用。手机的正常布局工作良好,10英寸平板电脑在两个方向上都可以很好地完成主细节布局。
如果这种做法有什么问题,请告诉我。谢谢。
发布于 2016-07-01 12:18:12
根据我的经验,我认为你应该为每个屏幕尺寸做一个布局,我认为你做到了这一点。setonContentView(.)之后这样做:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;并根据屏幕锁的高度和宽度来确定设备的方向。要锁定,可以添加以下行:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);为了不锁定屏幕,不要在android清单或活动中添加任何与屏幕方向相关的内容,默认情况下,旋转是启用的。
希望它能起作用,让我知道。
https://stackoverflow.com/questions/38144965
复制相似问题