感谢慕课网--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. 谈谈基于OAuth 2.0的第三方认证 [下篇]

    从安全的角度来讲,<中篇>介绍的Implicit类型的Authorization Grant存在这样的两个问题:其一,授权服务器没有对客户端应用进行认证,因为获取Access Token的 ...

  2. 将 instance 连接到 second_local_net - 每天5分钟玩转 OpenStack(85)

    今天是 local network 的最后一个小节,我们将验证两个local network 的连通性. launch 新的 instance “cirros-vm3”,网络选择 second_loc ...

  3. Form authentication(表单认证)问题

    前言 最近在做ASP.NET MVC中表单认证时出了一些问题,特此记录. 问题 进行表单认证时,在 PostAuthenticateRequest 事件中从Cookie值中解密票据.如下: prote ...

  4. Lua 学习笔记(十)数据结构

    在Lua中的table不是一种简单的数据结构,它可以作为其他数据结构的基础.其他语言提供的数据结构,如数组.记录.线性表.队列.集合等,在Lua中都可以通过table来表示.而且使用Lua实现这些数据 ...

  5. jar包依赖性查询

    项目中碰到jar包冲突,需要排除一些jar包时先要了解jar的依赖关系,maven提供了命令行来查询: mvn dependency:tree 返回依赖的属性结构

  6. kafka源码分析之二客户端分析

    客户端由两种:生产者和消费者 1. 生产者 先看一下生产者的构造方法: private KafkaProducer(ProducerConfig config, Serializer<K> ...

  7. 详解用Navicat工具将Excel中的数据导入Mysql中

    第一步:首先需要准备好有数据的excel: 第二步:选择"文件"->"另存为",保存为"CSV(逗号分隔)(*.csv)",将exce ...

  8. WebSocket in ASP.NET Core

    一.WebSocket WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算) 首先HTTP有1.1和1.0 ...

  9. Github团队开发示例(一)

    Github团队开发示例(二) 作者:Grey 原文地址:http://www.cnblogs.com/greyzeng/p/6044837.html 我们可以在Github上管理自己的团队项目.团队 ...

  10. MySQL 相关总结

    MySQL 优秀在线教程 RUNOOB-SQL 教程 MySQL 常用命令 导出操作 -- 某数据库 全部表 结构和数据 mysqldump -h192.168.8.152 -uroot -p man ...