安卓横竖屏切换后,应用只展示半屏问题 AndroidAutoSize

项目使用的是这个屏幕适配框架:GitHub - JessYanCoding/AndroidAutoSize: A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).

最近需要做一个特殊设备的横竖屏切换适配,发现了几个问题:

  1. 从横屏切换为竖屏时,只显示上半屏,下半屏是黑的
  2. 横竖屏切换时,没有重建Activity(AndroidManifest.xml中没有配置应用自行处理横竖屏切换,是让系统重建,但是系统并没有重建)
  3. 横竖屏切换时,onConfigurationChanged中给出的新的配置里面的屏幕方向仍然是横屏(也就是说系统不认为屏幕方向变化,没有重建Activity)

一度认为是固件问题,或者AndroidAutoSize框架问题,因为没有使用AndroidAutoSize的项目,就是好的,不会出现切换后半屏的问题。

最后发现问题原因是resizeableActivity这个属性。

官方文档:

Indicates that it is okay for this activity to be put in multi-window mode. Intended for a multi-window device where there can be multiple activities of various sizes on the screen at the same time.
The default value is false for applications with targetSdkVersion lesser than {@link android.os.Build.VERSION_CODES#N} and true otherwise.
Setting this flag to false lets the system know that the app may not be tested or optimized for multi-window environment. The system may still put such activity in multi-window with compatibility mode applied. It also does not guarantee that there will be no other apps in multi-window visible on screen (e.g. picture-in-picture) or on other displays. Therefore, this flag cannot be used to assure an exclusive resource access.
NOTE: A task's root activity value is applied to all additional activities launched in the task. That is if the root activity of a task is resizeable then the system will treat all other activities in the task as resizeable and will not if the root activity isn't resizeable.
NOTE: The value of {@link android.R.attr#screenOrientation} is ignored for resizeable activities when in multi-window mode.

翻译:

表示可以将此活动置于多窗口模式。适用于多窗口设备,在该设备中,屏幕上可以同时显示多种不同大小的活动。
对于targetSdkVersion小于{@link android.os.Build.VERSION_CODES#N}的应用程序,默认值为false,否则为true。
将此标志设置为false可以让系统知道应用程序可能未针对多窗口环境进行测试或优化。系统仍然可以在应用了兼容模式的多窗口中放置这样的活动。它也不能保证在屏幕上(如画中画)或其他显示器上不会看到多窗口中的其他应用程序。因此,此标志不能用于确保独占资源访问。
注意:任务的根活动值应用于任务中启动的所有其他活动。也就是说,如果任务的根活动是可调整的,那么系统会将任务中的所有其他活动视为可调整的;如果根活动不可调整,则系统不会。
注意:在多窗口模式下,可调整大小的活动将忽略{@link android.R.attr#screenOrientation}的值。

就是说跟应用的targetSdkVersion有关,targetSdkVersion小于24的,默认为false,表示该应用没有针对多窗口环境进行适配和优化。

24以上的默认为true。

可能是由于这个机型特殊,横屏切换为竖屏时,采用了多窗口模式,导致下半屏未显示内容。

android:resizeableActivity="true"

加上这个配置后,系统认为我们已针对多窗口做出优化,从而不会自行进入多窗口模式。

你可能感兴趣的:(android,android,横竖屏切换,屏幕适配,多窗口模式)