当我旋转我的手机时,我的活动重新开始。我有一个播放视频的视频视图,我旋转并重新启动视频。现在,我发现将这个添加到清单中的活动中可以修复它
<activity android:name="Vforum" android:configChanges="orientation"></activity>现在的问题是,视频控件不会被重新绘制,直到它们消失并返回,从而留下从横向到纵向模式的非常长的控件,或者从纵向到横向的非常短的控件。一旦它们消失,然后我点击让它们回来,然后它们的大小是正确的。有没有更好的方法呢?
发布于 2011-08-10 22:54:38
添加
android:configChanges="orientation"
你在AndroidManifest.xml中的活动。
如果您的目标应用编程接口级别为13或更高,则除了here中描述的orientation值之外,还必须包含screenSize值。因此,您的标记可能如下所示
android:configChanges="orientation|screenSize"发布于 2011-05-13 03:55:19
考虑记住视频文件在活动生命周期事件中的位置。创建Activity后,您可以获取视频位置,并从重新启动的那一刻开始播放。
在您的Activity类中:
@Override
protected void onCreate(Bundle bundle){
super.onCreate(bundle);
int mPos=bundle.getInt("pos"); // get position, also check if value exists, refer to documentation for more info
}
@Override
protected void onSaveInstanceState (Bundle outState){
outState.putInt("pos", myVideoView.getCurrentPosition()); // save it here
}发布于 2011-05-13 03:56:59
将configChanges属性添加到清单中意味着您将执行handle config changes yourself。覆盖活动中的onConfigurationChanged()方法:
int lastOrientation = 0;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks if orientation changed
if (lastOrientation != newConfig.orientation) {
lastOrientation = newConfig.orientation;
// redraw your controls here
}
}https://stackoverflow.com/questions/5983583
复制相似问题