使用ObjectAnimator开发打开、关闭书本动画

动画效果

动画效果-分享链接
(想做成gif图的,尝试各种工具无果)

ObjectAnimator简介及实现思路

 ObjectAnimator是从api level 11 (Android3.0x)增加的类。在11已下版本使用,你可以在工程中引入nineoldandroids包。
  这里直接翻译android文档的内容。
 This subclass of ValueAnimator provides support for animating properties on target objects. The constructors of this class take parameters to define the target object that will be animated as well as the name of the property that will be animated. Appropriate set/get functions are then determined internally and the animation will call these functions as necessary to animate the property.
 它是ValueAnimator的子类,提供对目标对象属性动画的支持。它的构造方法的参数包括要进行动画的目标对象以及进行动画的属性名。相应的set/get方法将在内部确定,必要时将调用它们进行动画。
实现思路

  比如打开第一张图粉红色位置的书,第二张图是中间过程。
  动画分为三部分,褐色部分为背景(可以为背景设置不同的纯色),黄色部分为封面,灰色部分为加载图标
  这三部分分别要新建一个ImageView,加入到FrameLayout中,使用WindowManager显示在屏幕上。

  • 背景动画:从A移动到B(translationX, translationY属性),同时放大(scaleX,scaleY属性);
  • 封面动画:从A移动到B,同时放大,旋转(rotationY);
  • 加载图标:在屏幕居中,从0放大到1;

关闭动画属性值与打开动画真好相反。

遇到的问题:

  1. 动画轴点(pivotX, pivotY)使用默认的(0, 0)即可;
  2. y方向放大比例大时,x方向需要做平移,使view居中;
  3. 背景控件的布局参数不能为wrap_content, 否则,因其使用ColorDrawable作为背景,它将不可见;也不能是match_parent, 否则,它将填充屏幕。所以要为它指定宽、高。

主要代码

BookView.java

package com.example.openbookanimationproj;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import com.example.openbookanimationproj.R;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.Animator.AnimatorListener;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ListView;
import android.widget.RelativeLayout;

/**
 * A view to show the cover of a book. With method
 * {@link BookView#startOpenBookAnimation(OpenBookAnimEndListener, ViewParent)} and method
 * {@link BookView#startCloseBookAnimation()} to play opening and closing book animations.
 * 
 * @author wenping0820@163.com
 * @date 2015-07-13
 */
public class BookView extends RelativeLayout implements AnimatorListener {
   
    public static BookView sOpenedBookView;
    // Opening book animation duration
    private static final int OPEN_ANIMATION_DURATION = 500;
    // Closing book animation duration
    public static final int CLOSE_ANIMATION_DURATION = 500;
    // Animation background scales
    private float mB
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
《汽车系统开发OSEK》是一本介绍汽车电子控制系统开发的专业书籍。该书内容包括了汽车系统的控制策略、软件架构和技术细节等方面的知识。 首先,该书详细介绍了OSEK(Open Systems and the Corresponding Interfaces for Automotive Electronics)标准,它是汽车行业的一个通用标准,用于定义汽车中的电子控制器之间的接口和交互规范。通过遵循OSEK标准,汽车制造商和供应商能够更方便地开发和整合各种电子控制单元,提高汽车系统的可靠性和稳定性。 其次,本书还讲解了汽车系统开发的软件架构,该框架通常由不同的软件模块组成,包括应用软件、操作系统、驱动程序和通信协议等。通过了解这些模块的功能和相互之间的关系,读者可以更好地掌握汽车系统开发的方法和技术。 此外,本书还涵盖了实际开发过程中的关键问题和技术挑战。例如,面对汽车系统复杂性的挑战,如何有效管理和调度各个任务的执行;如何确保软件的可靠性和安全性,防止潜在的故障和攻击;如何进行软件测试和调试,以确保系统的正确运行等等。通过学习这些经验和技巧,读者可以更好地应对汽车系统开发中的各种问题和挑战。 综上所述,《汽车系统开发OSEK》是一本全面介绍汽车电子控制系统开发的重要参考书籍,它可以帮助读者了解汽车系统的控制策略、软件架构和技术细节,并为读者提供解决问题的方法和技巧。无论是对汽车电子工程师还是对汽车系统开发感兴趣的读者来说,这都是一本值得阅读的书籍。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值