2013-02-06 44 views
12

Tôi muốn tạo hoạt ảnh cho Flipboard trong khi thay đổi chế độ xem trong Android.Hoạt ảnh trên Android Flipboard

Có thể tạo hoạt ảnh cho Flipboard trên toàn bộ bố cục không? Một cái gì đó tương tự như những chữ cái trên hình ảnh nhưng toàn bộ bố cục.

Ví dụ:

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

// whole layout design 

<LinearLayout/> 

Tôi muốn thực hiện một hình ảnh động khi thay đổi Layout này và/hoặc lạm phát khác để làm hình ảnh động Flipboard.

Flipboard animation

Các hoạt hình nên trông giống hệt như this one

+1

http://code.google.com/p/android-3d-flip-view-transition/ – dilix

+0

@dilix Tôi đang tìm Hoạt ảnh như thế này http://www.youtube.com/watch?v= w1fTI7oYfbI – Naskov

+2

Tôi nghĩ bài đăng này hữu ích: http://openaphid.github.com/blog/2012/05/21/how-to-implement-flipboard-animation-on-android/ – dilix

Trả lời

2

Câu trả lời của câu hỏi này là trên GitHub. Một ví dụ rất hay được cung cấp bởi OpenAphid. Truy cập vào link này.

+0

Giải pháp này không hoạt động giữa các hoạt động, phải không? – Billda

+0

@Billda này đã được hỏi một năm trước, cho đến bây giờ bạn có thể tìm thấy một cách khác để làm điều này hình ảnh động, và, uhm, tôi đã không cố gắng rằng kể từ khi tất cả mọi thứ đang đi xung quanh với mảnh vỡ. – Naskov

+0

Tôi tin rằng bạn, nhưng tôi không biết làm thế nào để thực hiện nó với các mảnh không phải .. Bởi vì giải pháp openAphid hoạt động trong một hoạt động/phân đoạn, phải không? – Billda

1

Sử dụng sau Codes Họ là chính xác cho yêu cầu của bạn:

Lớp 1:

import android.graphics.Color; 
import android.view.Display; 
import android.view.View; 
import android.view.WindowManager; 
import android.view.animation.AccelerateInterpolator; 
import android.view.animation.Animation; 

    /** 
    * A class that is responsible switching the mode with the flip animation 
    */ 

    public class ViewSwitcher { 

     private final static int DURATION = 500; 
     private final static float DEPTH = 400.0f; 

     public interface AnimationFinishedListener { 
      /** 
      * Called when the animation is finished. 
      */ 
      public void onAnimationFinished(); 
     } 

     public static void animationIn(View container, WindowManager windowManager) { 
      animationIn(container, windowManager, null); 
     } 

     public static void animationIn(View container, WindowManager windowManager, AnimationFinishedListener listener) { 
      apply3DRotation(90, 0, false, container, windowManager, listener); 
     } 

     public static void animationOut(View container, WindowManager windowManager) { 
      animationOut(container, windowManager, null); 
     } 

     public static void animationOut(View container, WindowManager windowManager, AnimationFinishedListener listener) { 
      apply3DRotation(0, -90, true, container, windowManager, listener); 
     } 

     private static void apply3DRotation(float fromDegree, float toDegree, boolean reverse, View container, WindowManager windowManager, final AnimationFinishedListener listener) { 
      Display display = windowManager.getDefaultDisplay(); 
      final float centerX = display.getWidth()/2.0f; 
      final float centerY = display.getHeight()/2.0f; 

      final Rotate3dAnimation a = new Rotate3dAnimation(fromDegree, toDegree, centerX, centerY, DEPTH, reverse); 
      a.reset(); 
      a.setBackgroundColor(Color.WHITE); 
      a.setDuration(DURATION); 
      a.setFillAfter(true); 
      a.setInterpolator(new AccelerateInterpolator()); 
      if (listener != null) { 
       a.setAnimationListener(new Animation.AnimationListener() { 
        public void onAnimationStart(Animation animation) { 
        } 

        public void onAnimationRepeat(Animation animation) { 
        } 

        public void onAnimationEnd(Animation animation) { 
         listener.onAnimationFinished(); 
        } 
       }); 
      } 
      if(container != null){ 
       container.clearAnimation(); 
       container.startAnimation(a); 
      } 
      else if (listener != null) 
       listener.onAnimationFinished(); 
     } 
    } 

lớp 2:

import android.view.animation.Animation; 
import android.view.animation.Transformation; 
import android.graphics.Camera; 
import android.graphics.Color; 
import android.graphics.Matrix; 

/** 
* An animation that rotates the view on the Y axis between two specified angles. 
* This animation also adds a translation on the Z axis (depth) to improve the effect. 
*/ 
public class Rotate3dAnimation extends Animation { 
    private final float mFromDegrees; 
    private final float mToDegrees; 
    private final float mCenterX; 
    private final float mCenterY; 
    private final float mDepthZ; 
    private final boolean mReverse; 
    private Camera mCamera; 

    /** 
    * Creates a new 3D rotation on the Y axis. The rotation is defined by its 
    * start angle and its end angle. Both angles are in degrees. The rotation 
    * is performed around a center point on the 2D space, definied by a pair 
    * of X and Y coordinates, called centerX and centerY. When the animation 
    * starts, a translation on the Z axis (depth) is performed. The length 
    * of the translation can be specified, as well as whether the translation 
    * should be reversed in time. 
    * 
    * @param fromDegrees the start angle of the 3D rotation 
    * @param toDegrees the end angle of the 3D rotation 
    * @param centerX the X center of the 3D rotation 
    * @param centerY the Y center of the 3D rotation 
    * @param reverse true if the translation should be reversed, false otherwise 
    */ 
    public Rotate3dAnimation(float fromDegrees, float toDegrees, 
      float centerX, float centerY, float depthZ, boolean reverse) { 
     super.setBackgroundColor(Color.WHITE); 
     mFromDegrees = fromDegrees; 
     mToDegrees = toDegrees; 
     mCenterX = centerX; 
     mCenterY = centerY; 
     mDepthZ = depthZ; 
     mReverse = reverse; 
    } 

    @Override 
    public void initialize(int width, int height, int parentWidth, int parentHeight) { 
     super.setBackgroundColor(Color.WHITE); 
     super.initialize(width, height, parentWidth, parentHeight); 
     mCamera = new Camera(); 
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     super.setBackgroundColor(Color.WHITE); 
     final float fromDegrees = mFromDegrees; 
     float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); 

     final float centerX = mCenterX; 
     final float centerY = mCenterY; 
     final Camera camera = mCamera; 
     final Matrix matrix = t.getMatrix(); 

     camera.save(); 
     if (mReverse) { 
      camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime); 
     } else { 
      camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime)); 
     } 
     camera.rotateX(degrees); 
     camera.getMatrix(matrix); 
     camera.restore(); 

     matrix.preTranslate(-centerX, -centerY); 
     matrix.postTranslate(centerX, centerY); 

    } 
} 

Class 3:

This Will be Your Actual activity where you should call following two calls to AnimationOut and AnimationIn with passing old view, new view respectively whenever you require to make your disered animation. 

Bây giờ Gọi animationOut với số đầu tiên là quan điểm Cũ phải được loại bỏ như dưới đây:

ViewSwitcher.animationOut(this.findViewById(android.R.id.content1), getWindowManager(), new ViewSwitcher.AnimationFinishedListener() { 
      public void onAnimationFinished() { 
      //Do Something here before removing this view from screen if required. 
      } 
     }); 

Bây giờ Gọi animationIn với số đầu tiên là xem mới được được hiển thị như bên dưới:

ViewSwitcher.animationIn(this.findViewById(android.R.id.content2), this.getWindowManager()); 
+2

Tôi đã upvoted nhưng tôi vẫn đang cố gắng định cấu hình hoạt ảnh này để chia View của tôi làm đôi làm chính xác tôi đang tìm kiếm. Btw các snipped là tuyệt vời. Tôi sẽ chấp nhận câu trả lời nếu tôi quản lý chia tách chế độ xem một nửa :) – Naskov

+0

Hoạt ảnh sẽ trông giống hệt như thế này http://www.youtube.com/watch?v=w1fTI7oYfbI .. – Naskov

+2

@Naskov Để tách chế độ xem của bạn thành một nửa và làm thay đổi chính xác các góc. Tôi nghĩ rằng có thể làm điều đó. –

Các vấn đề liên quan