感谢慕课网--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. Tomcat报java.lang.OutOfMemoryError: Java heap space错误停止运行如何解决

    最近开发的一个商业项目,部署完成后,经常出现Tomcat挂掉的现象,报的异常是:java.lang.OutOfMemoryError: Java heap space,上网google了一下,了解了一 ...

  2. 2014年百度之星程序设计大赛 - 初赛(第二轮)JZP Set

    题目描述:一个{1, ..., n}的子集S被称为JZP集,当且仅当对于任意S中的两个数x,y,若(x+y)/2为整数,那么(x+y)/2也属于S.例如,n=3,S={1,3}不是JZP集,因为(1+ ...

  3. Oracle函数之LISTAGG

    最近在学习的过程中,发现一个挺有意思的函数,它可实现对列值的拼接.下面我们来看看其具体用法. 用法: 对其作用,官方文档的解释如下: For a specified measure, LISTAGG  ...

  4. golang操作文件

    1.读取文件信息: /* 读取文件信息 */ func readFile(path string) string { fi, err := os.Open(path) if err != nil { ...

  5. Java内存模型深度解析:重排序 --转

    原文地址:http://www.codeceo.com/article/java-memeory-2.html 数据依赖性 如果两个操作访问同一个变量,且这两个操作中有一个为写操作,此时这两个操作之间 ...

  6. 第一章 Linux內核簡介

    1. Linux是類Unix系統,但他不是Unix. 儘管Linux借鑑了Unix的許多設計並且實現了Unix的API(由Posix標準和其他Single Unix Specification定義的) ...

  7. cordova plugin add出现CERT_UNTRUSTED错误解决方法

    介绍 目前使用ionic+cordova完成hybmid app开发,在安装geolocation插件时爆出来一个莫名的错误: Fetching from npm failed: CERT_UNTRU ...

  8. Oracle丢失重做日志的几种场景恢复

    实验环境:RHEL6.4 + Oracle 11.2.0.4 一.丢失重做日志组中成员 1.1 故障模拟 1.2 处理方法 1.3 实际处理过程 二.丢失重做日志组 2.1 丢失INACTIVE重做日 ...

  9. 1Z0-053 争议题目解析685

    1Z0-053 争议题目解析685 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 685.In your test database: -You are using Recover ...

  10. 【面试】输出"蛇形"矩阵

    一.题目描述 腾讯实习在线笔试的一道题目. 根据输入的数字(< 1000),输出这样的"蛇形"矩阵,如下.输入n,输出(n * n)阶矩阵,满足由外到内依次增大. 如: 输入 ...