2025-02-10

 

在實際應用中,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.aiwalls.com

42.                    startAnimation(anim);

43.                mOrientation = orientation;

44.            }

45.       }

這個地方完成瞭平滑的實現

 摘自:enlife 的BLOG

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *