感谢慕课网--eclipse_xu

布局文件:activity_main.xml

 <FrameLayout 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"
tools:context="com.example.animationapp.MainActivity" > <ImageView
android:id="@+id/im0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/b" /> <ImageView
android:id="@+id/im1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/c" /> <ImageView
android:id="@+id/im2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/d" /> <ImageView
android:id="@+id/im3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/e" /> <ImageView
android:id="@+id/im4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/f" /> <ImageView
android:id="@+id/im5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/g" /> <ImageView
android:id="@+id/im6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:src="@drawable/h" /> <ImageView
android:id="@+id/im7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/a" /> </FrameLayout>

图片资源

MainActivity.java

 package com.example.animationapp;

 import java.util.ArrayList;
import java.util.List; import android.support.v7.app.ActionBarActivity;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import android.widget.Toast; public class MainActivity extends ActionBarActivity implements OnClickListener { private int[] res = {R.id.im0, R.id.im1,R.id.im2,
R.id.im3,R.id.im4,R.id.im5,R.id.im6,R.id.im7}; private List<ImageView> list = new ArrayList<ImageView>(); private boolean flag = true; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initView();
} private void initView() { for(int i = 0; i < res.length; i++){
ImageView im = (ImageView) findViewById(res[i]);
im.setOnClickListener(this);
list.add(im);
}
} @Override
public void onClick(View v) {
switch(v.getId()){
//im7最后布局,叠加在最上面
case R.id.im7:{ if(flag){
startAnimation();
flag = false;
}else{
closeAnimation();
flag = true;
}
break;
} default:
Toast.makeText(MainActivity.this, v.getId()+"OK", Toast.LENGTH_SHORT).show();
break;
}
} private void closeAnimation() {
for(int i = 0 ;i<res.length-1; i++){
ObjectAnimator oa = ObjectAnimator.ofFloat(list.get(i),
"translationY",i*200F, 0F );
oa.setDuration(100);
//oa.setStartDelay(50*i);
oa.start();
}
} private void startAnimation() {
//此处只需要弹出其余7个图标,最上边的图标im7不动
for(int i = 0 ;i<res.length-1; i++){
//属性动画操作类
ObjectAnimator oa = ObjectAnimator.ofFloat(list.get(i),
"translationY", 0F, i*200F);
oa.setDuration(200);
//oa.setInterpolator(new BounceInterpolator());
//oa.setStartDelay(200*i);
oa.start();
}
} }

ObjectAnimator属性动画应用demo的更多相关文章

  1. ObjectAnimator属性动画示例代码

    import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.app.Ac ...

  2. Android属性动画之第一重修炼总结

    经过这两天对ObjectAnimator属性动画的学习,基本对Android提供的属性动画有了一定的认识,现在就为大家以一个类似扇形打开的效果做总结. 效果图: 下面就让我们用刚刚学到的属性动画效果, ...

  3. Android 属性动画框架 ObjectAnimator、ValueAnimator ,这一篇就够了

    前言 我们都知道 Android 自带了 Roate Scale Translate Alpha 多种框架动画,我们可以通过她们实现丰富的动画效果,但是这些宽家动画却有一个致命的弱点,它们只是改变了 ...

  4. Android基础夯实--重温动画(五)之属性动画 ObjectAnimator详解

    只有一种真正的英雄主义 一.摘要 ObjectAnimator是ValueAnimator的子类,它和ValueAnimator一样,同样具有计算属性值的功能,但对比ValueAnimator,它会更 ...

  5. 【转】android 属性动画之 ObjectAnimator

    原文网址:http://blog.csdn.net/feiduclear_up/article/details/39255083 前面一篇博客讲解了 android 简单动画之 animtion,这里 ...

  6. Android属性动画之ObjectAnimator

    相信对于Android初学者,对于Android中的动画效果一定很感兴趣,今天为大家总结一下刚刚学到的属性动画案例. 首先和一般的Android应用一样,我们先建一个工程,为了方便,我们的布局文件中就 ...

  7. Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...

  8. android 开发 View _2_ View的属性动画ObjectAnimator ,动画效果一览

    支持:https://www.cnblogs.com/whoislcj/p/5738478.html translationX的效果: protected void onCreate(Bundle s ...

  9. Android 属性动画ObjectAnimator和ValueAnimator讲解

    区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view  ,view自己做改变. ...

随机推荐

  1. 应用程序框架实战三十八:项目示例VS解决方案的创建(一)

    进行项目开发的第一步,是创建出适合自己团队习惯的VS解决方案,虽然我已经提供了项目示例,但毕竟是我创建的,你直接使用可能并不合适,另外你如果尝试模仿重新创建该示例,中间可能碰到各种障碍,特别是项目间的 ...

  2. 自己实现简单的string类

    1.前言 最近看了下<C++Primer>,觉得受益匪浅.不过纸上得来终觉浅,觉知此事须躬行.今天看了类类型,书中简单实现了String类,自己以前也学过C++,不过说来惭愧,以前都是用C ...

  3. matlab基础教程——根据Andrew Ng的machine learning整理

    matlab基础教程--根据Andrew Ng的machine learning整理 基本运算 算数运算 逻辑运算 格式化输出 小数位全局修改 向量和矩阵运算 矩阵操作 申明一个矩阵或向量 快速建立一 ...

  4. SQLServer学习笔记系列11

    一.写在前面的话 身体是革命的本钱,这句放在嘴边常说的话,还是拿出来一起共勉,提醒一起奋斗的同僚们,保证睡眠,注意身体!偶尔加个班,也许不曾感觉到身体发出的讯号,长期晚睡真心扛不住!自己也制定计划,敦 ...

  5. TP框架执行流程分许

    1. index.php 入口文件 2. ThinkPHP/ThinkPHP.php 在php5.3版本以后 设置常量有两种方式: const name = value; 作用域根据当前命名空间决定 ...

  6. scikit-learn一般实例之一:绘制交叉验证预测

    本实例展示怎样使用cross_val_predict来可视化预测错误: # coding:utf-8 from pylab import * from sklearn import datasets ...

  7. ActiveX(四) mshtml 命名空间 重要接口简介

    在上一篇随笔 ActiveX(三)ActiveX 调用 Js 中,我们已经可以获得js中window对象的强类型接口.即 mshtml.IHTMLWindow2 ,通过该接口.我们可以调用js函数.那 ...

  8. Winform分页控件

    设计界面: 控件代码: using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...

  9. 高效率去掉js数组中重复项

    Array类型并没有提供去重复的方法,如果要把数组的重复元素干掉,那得自己想办法: function unique(arr) { var result = [], isRepeated; for (v ...

  10. string转byte[]

    static byte[] GetBytes(string str) { byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buff ...