我刚刚实现了方向改变功能 - 例如当布局从纵向变为横向时(反之亦然)。如何检测方向更改事件何时完成。
The OrientationEventListener
没用。如何获取有关布局方向更改事件的通知?
Use the onConfigurationChanged
Activity 的方法 - 如中所述Android 文档中的“处理运行时更改”指南 http://web.archive.org/web/20120805085007/http://developer.android.com/guide/topics/resources/runtime-changes.html:
@Override public void onConfigurationChanged(@NotNull Configuration
newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
} }
您还必须编辑适当的你的元素
清单文件包括android:配置更改:
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
NOTE:对于 Android 3.2(API 级别 13)或更高版本,当设备在纵向和横向之间切换时,“屏幕尺寸”也会发生变化
方向。因此,如果您想防止运行时由于以下原因重新启动
在针对 API 级别 13 或更高级别进行开发时,方向会发生变化,您
必须声明API 的 android:configChanges="orientation|screenSize"
13级或以上.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)