android 細節之 旋轉動畫

來源:互聯網
上載者:User

標籤:android   blog   os   java   io   for   ar   2014   art   


Flip Animation for Android:


近期項目中用到了一個小動畫,讓物體實現一定的3D旋轉效果,現記錄例如以下:


public class FlipAnimation extends Animation {    private Camera mCamera;    private View mFromView;    private View mToView;    private float mCenterX;    private float mCenterY;    private boolean mForward = true;    /**     * Creates a 3D flip animation between two views.     *     * @param fromView First view in the transition.     * @param toView Second view in the transition.     */    public FlipAnimation(View fromView, View toView) {        mFromView = fromView;        mToView = toView;        setDuration(700);        setFillAfter(false);        setInterpolator(new AccelerateDecelerateInterpolator());    }    public void reverse() {        mForward = false;        View switchView = mToView;        mToView = mFromView;        mFromView = switchView;    }    @Override    public void initialize(int width, int height, int parentWidth, int parentHeight) {        super.initialize(width, height, parentWidth, parentHeight);        mCenterX = width / 2;        mCenterY = height / 2;        mCamera = new Camera();    }    @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {        final double radians = Math.PI * interpolatedTime;        float degrees = (float)(180.0 * radians / Math.PI);        if (interpolatedTime >= 0.5f) {            degrees -= 180.f;            mFromView.setVisibility(View.GONE);            mToView.setVisibility(View.VISIBLE);        }        if (mForward) {            degrees = -degrees;        }        final Matrix matrix = t.getMatrix();        mCamera.save();        mCamera.rotateY(degrees);        mCamera.getMatrix(matrix);        mCamera.restore();        matrix.preTranslate(-mCenterX, -mCenterY);        matrix.postTranslate(mCenterX, mCenterY);    }}


android 細節之 旋轉動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.