在实际应用中,android2.3的浏览器中添加了横竖屏切换的平滑滑动的效果。
Browser的AndroidManifest.xml中
1.<activity android:name="BrowserActivity"
2.android:label="@string/application_name"
3.android:launchMode="singleTask"
4.android:alwaysRetainTaskState="true"
5.android:configChanges="orientation|keyboardHidden"
6.android:theme="@style/BrowserTheme"
7.android:windowSoftInputMode="adjustResize" >
可以看到配置了android:configChanges="orientation|keyboardHidden"属性,而在BrowserActivity的onConfigurationChanged()方法中没发现有关于页面重绘的操作。而在framework/base/core/java/android/webkit文件夹中的webview中的
1.protected void onConfigurationChanged (Configuration newConfig) {
2.
3.super.onConfigurationChanged(newConfig);
4.
5.int preRotateWidth;
6.int preRotateHeight;
7.
8.Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
9.preRotateWidth = display.getWidth();
10.preRotateHeight = display.getHeight();
11.int orientation = display.getRotation();
12.orientation = orientation * 90;
13.
14.if (orientation != mOrientation)
15.{
16.float angle = (float)(mOrientation - orientation);
17.if (angle > 180.0f)
18.{
19.angle -= 360.0f;
20.}
21.else if (angle < -180.0f)
22.{
23.angle += 360.0f;
24.}
25.//smooth rotate
26.RotateAnimation anim = new RotateAnimation(angle, TO_DEGREES,
27.Animation.RELATIVE_TO_PARENT, PIVOT_X_VALUE, Animation.RELATIVE_TO_PARENT, PIVOT_Y_VALUE);
28.OvershootInterpolator interp = new OvershootInterpolator(OVERSHOOT_TENSION);
29.anim.setDuration(ANIMATION_DURATION);
30.anim.setFillEnabled(true);
31.anim.initialize(preRotateWidth,preRotateHeight,preRotateWidth,preRotateHeight);
32.anim.setInterpolator(interp);
33.anim.setAnimationListener(new SmoothRotateAnimationListener());
34.ViewParent parent = getParent();
35.// Find the parent view so that, if it is a View class (it can be ViewRoot class), then it's
36.// preferable to start the animation on the parent because the parent View can cache its children
37.// during animation. If Webview has no parent View, then the animation will be done by itself -
38.// meaning that it will have to do the rotation and will be slow.
39.if (parent instanceof View)
40.((View)parent).startAnimation(anim);
41.else www.2cto.com
42.startAnimation(anim);
43.mOrientation = orientation;
44.}
45.}
这个地方完成了平滑的实现
摘自:enlife 的BLOG