多种动画效果的结合使用方法以及Interpolator简介

Interpolator的两种用法属性

1.在xml中设置android:interpolator="@android:anim/accelerate_decelerate_interpolator"

2.在.java文件中设置,有两种情况

若设置为true,则统一interpolator速度;

AnimationSet animationSet = new AnimationSet(true);

若设置为false,则需要单独为各个动画设置interpolator

AnimationSet animationSet = new AnimationSet(false);
AlphaAnimation alpha = new AlphaAnimation(1.0f,0.0f);
RotateAnimation rotate = new RotateAnimation(0, 360,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
alpha.setInterpolator(new AccelerateInterpolator());
rotate.setInterpolator(new AccelerateInterpolator());

alpha动画和rotate动画结合使用

MainActivity.java

public class MainActivity extends Activity {

    private Button button = null;
    private ImageView imageView = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        imageView = (ImageView)findViewById(R.id.imageViewId);
        button = (Button)findViewById(R.id.scaleButtonId);
        button.setOnClickListener(new AnimationButtonListener());
    }

    private class AnimationButtonListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            /**
            Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha);
            imageView.startAnimation(animation);
            */
            AnimationSet animationSet = new AnimationSet(true);
            AlphaAnimation alpha = new AlphaAnimation(1.0f,0.0f);
            RotateAnimation rotate = new RotateAnimation(0, 360,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animationSet.addAnimation(alpha);
            animationSet.addAnimation(rotate);
            animationSet.setDuration(2000);
            animationSet.setStartOffset(500);
            imageView.startAnimation(animationSet);
        }
    }
}

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.shen.animation04.MainActivity" >

    <Button
        android:id="@+id/scaleButtonId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="测试动画效果"/>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/imageViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:src="@drawable/ic_launcher"/>
    </LinearLayout>

</RelativeLayout>

group.xml(alpha&rotate)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:shareInterpolator="true">

    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:startOffset="500"
        android:duration="2000"/>

    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000"/>

</set>
时间: 2024-08-10 17:17:39

多种动画效果的结合使用方法以及Interpolator简介的相关文章

NiftyDialogEffects:集成了多种动画效果的Dialog控件

在这个网站上有很多用js实现的对话框效果:http://tympanus.net/Development/ModalWindowEffects/ 现在有人做出了相同效果的android版本,几乎和上面的一模一样,界面如下: 动画效果: 要查看更多的动画效果请参考上面给出的网站链接. 该项目的git地址为:https://github.com/sd6352051/NiftyDialogEffects 可能该项目是用android studio创建的吧,但是因为被墙的原因android studio

实用CSS3的transform实现多种动画效果

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="http://keleyi.com"> <title>实用CSS3的transform实现多种动画效果-柯乐义</title><base target="_blank" /> <s

iOS的动画效果类型及实现方法

实现iOS漂亮的动画效果主要有两种方法, 一种是UIView层面的, 一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransition进行了封装,它只能用于一些简单的.常用的效果展现,这里写一个常用的示例代码,供大家参考. [UIView beginAnimations:@"Curl"context:nil];//动画开始 [UIView setAnimationDuration:0.75]; [UIView se

仿映客客户端、TableView多种动画效果、边缘返回手势等源码

iOS精选源码 相册多选框架 zhPopupController 简单快捷弹出自定义视图 tableView实现多种动画效果 自定义动画的PageControl 展示tableView和collectionView的结构,框架CHD_ListView_Structure RxSwift+Moya+ObjectMapper优雅的网络请求级模型转换 多种指示器文字效果源码SGPagingView react-native低仿映客直播客户端 支持iOS/Android ScreenEdgePanGes

jQuery 的动画效果图片----隐藏打开方法

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery-3.2.1.js"></script> </head> <body> <img src="22.jpg&q

IOS开发-UIView之动画效果的实现方法(合集)

http://www.cnblogs.com/GarveyCalvin/p/4193963.html 前言:在开发APP中,我们会经常使用到动画效果.使用动画可以让我们的APP更酷更炫,最重要的是优化用户体验,但取决于动画的质量.像QQ.微信.新浪微博等APP,动画效果就很好了,至少我很喜欢它们的动画,让我使用起来感觉很顺畅,心情很开朗.本文会介绍UIView效果的实现方法,非核心动画. 一.使用UIView类实现动画 基本写法,代码必须放在Begin和Commit之间: [UIView beg

200多种Android动画效果的强悍框架

admin 发布于2015-10-23 14:33 363/68015 [精品推荐]200多种Android动画效果的强悍框架,太全了,不看这个,再有动画的问题,不理你了^@^ 功能模块和技术方案 只看楼主 楼层直达 200多种Android动画效果的强悍框架,太全了 概要: Android近200多种动画效果集合框架源码,太全了,总有你需要的,木有你找不到的,相当强悍,非常棒的产品开发原型参考和学习资料 主要功能列表: 1)Splash动画 (中心打开式效果 ) 2)Flip折叠效果的集合(1

200多种Android动画效果的强悍框架,总有你想要的

Android近200多种动画效果集合框架源码,太全了,总有你需要的,木有你找不到的,相当强悍,非常棒的产品开发原型参考和学习资料 主要功能列表: 1)Splash动画 (中心打开式效果 ) 2)Flip折叠效果的集合(13种) 3)NineOld集合(18+) 4)高仿系列(6种经典动画),火车票出票动画 淘宝菜单 优酷导航菜单 图片3D浏览 下拉选择框 扫雷效果: 5)简单动画(24种): 6)复杂动画(43种): 7)Splash引导动画(5种). Demo: 太全了,别嫌多哈,只需要找你

JS函数库:页面滚动过程中元素产生动画效果 WOW.js

官网 WOW.js依赖animate.css, 所以它支持animate.css多达60多种动画效果. 浏览器兼容:IE9以及以前的版本不适用 使用方法: 1.引入文件 <link rel="stylesheet" href="css/animate.min.css" /> <script type="text/javascript" src="js/wow.min.js"></script>