Android N如何在系统屏幕缩放/显示尺寸更改时拒绝按比例缩放的布局

问题描述:

我的应用"具有一些复杂的布局,希望它们不会在Android N的大"显示尺寸中缩放.

My App has some complex layouts that hope not to be scaled in "Large" display size of Android N.

我只是想到了一种愚蠢的方法,可以通过屏幕密度来计算合适的缩放比例,迭代每个布局视图并为每个视图重置LayoutParameters.

I just thought a stupid method to calculate the suitable scale ratio by screen density, iterate each view of layout, and reset the LayoutParameters for each view.

我的问题是,这是开发的常见问题/要求,是否有任何api或布局设置来拒绝这些布局中的显示尺寸"更改?

My question is, this is a common issue/requirement for develop, is there any api or layout setting to deny the "display size" change in those layouts?

该文档尚未更新.您可以在此处找到此新功能的说明(屏幕缩放),但是无法知道如何不支持它.

the doc is not updated yet on that. It's possible find a description of this new functionality here (Screen Zoom), but there's no way to know how not support it.

您可以通过将一些参数添加到configChanges中来决定处理配置更改.文档中还没有秘密"值密度",但可以正常工作.只需将清单中的这一行添加到您的活动中即可.

You can decide to handling the configuration change by yourself adding some parameters to your configChanges. There is a "secret" value "density" not yet in the doc but works as expected. Just add this line in the manifest to your activity.

<activity
    android:name=".MyActivity"
    android:configChanges="density"/>

如果您要自己管理多窗口模式,我建议也使用这些.因此,您的代码可能会像这样更好:

I suggest to use also these if you want to manage by yourself the Multi-WIndow mode. So your code could be better like this:

<activity
    android:name=".MyActivity"
    android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|density"/>