ObjectAnimator属性动画应用demo
感谢慕课网--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的更多相关文章
- ObjectAnimator属性动画示例代码
import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.app.Ac ...
- Android属性动画之第一重修炼总结
经过这两天对ObjectAnimator属性动画的学习,基本对Android提供的属性动画有了一定的认识,现在就为大家以一个类似扇形打开的效果做总结. 效果图: 下面就让我们用刚刚学到的属性动画效果, ...
- Android 属性动画框架 ObjectAnimator、ValueAnimator ,这一篇就够了
前言 我们都知道 Android 自带了 Roate Scale Translate Alpha 多种框架动画,我们可以通过她们实现丰富的动画效果,但是这些宽家动画却有一个致命的弱点,它们只是改变了 ...
- Android基础夯实--重温动画(五)之属性动画 ObjectAnimator详解
只有一种真正的英雄主义 一.摘要 ObjectAnimator是ValueAnimator的子类,它和ValueAnimator一样,同样具有计算属性值的功能,但对比ValueAnimator,它会更 ...
- 【转】android 属性动画之 ObjectAnimator
原文网址:http://blog.csdn.net/feiduclear_up/article/details/39255083 前面一篇博客讲解了 android 简单动画之 animtion,这里 ...
- Android属性动画之ObjectAnimator
相信对于Android初学者,对于Android中的动画效果一定很感兴趣,今天为大家总结一下刚刚学到的属性动画案例. 首先和一般的Android应用一样,我们先建一个工程,为了方便,我们的布局文件中就 ...
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...
- android 开发 View _2_ View的属性动画ObjectAnimator ,动画效果一览
支持:https://www.cnblogs.com/whoislcj/p/5738478.html translationX的效果: protected void onCreate(Bundle s ...
- Android 属性动画ObjectAnimator和ValueAnimator讲解
区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view ,view自己做改变. ...
随机推荐
- 为 Neutron 准备物理基础设施(I) - 每天5分钟玩转 OpenStack(75)
前面讨论了 Neutron 的架构和基础知识,接下来就要通过实验深入学习和实践了. 第一步就是准备实验用的物理环境,考虑如下几个问题: 需要几个节点? 如何分配节点的角色? 节点上部署哪些服务? 配几 ...
- AngularJs 动态加载模块和依赖
最近项目比较忙额,白天要上班,晚上回来还需要做Angular知识点的ppt给同事,毕竟年底要辞职了,项目的后续开发还是需要有人接手的,所以就占用了晚上学习的时间.本来一直不打算写这些第三方插件的学习笔 ...
- MySQL学习笔记十四:优化(1)
SQL优化 1.查看各种SQL执行的频率 mysql> show status like 'Com_select';--Com_insert,Com_delete,connections(试图连 ...
- angularjs 请求后端接口请求了两次
用angularjs的过程中发现,每次打开页面,请求后端的接口都请求了两次 如下图可以看到, http://192.168.1.109:8080/zdh/api/v1/goods/54 这个页面loa ...
- CSS3知识点整理&&一些demo
css3能做什么 响应式开发的基础,然后能实现一些酷炫的效果咯. 以下案例纯css3实现,一点都没用js (入门简单,但是水很深) 叮当猫纯用css3做出 http://codepen ...
- 多个 App 间启动
http://developer.nokia.com/: URI associations for Windows Phone http://msdn.microsoft.com/: Auto-lau ...
- 让你分分钟学会Javascript中的闭包
Javascript中的闭包 前面的话: 闭包,是 javascript 中重要的一个概念,对于初学者来讲,闭包是一个特别抽象的概念,特别是ECMA规范给的定义,如果没有实战经验,你很难从定义去理解它 ...
- 4.DB Initialization(数据库初始化)[EF Code-First系列]
前面的例子中,我们已经看到了Code-First自动为我们创建数据库的例子. 这里我们将要学习的是,当初始化的时候,Code-First是怎么决定数据库的名字和服务的呢??? 下面的图,解释了这一切! ...
- STM32Cube Uart_DMA测试工程
1.打开软件,新建工程,选择芯片信号,这里选择 2.USART1使能选择"Asynchronous"模式: 3.配置"RCC",High ...
- hotcss用法
1.0 GitHub下载地址: https://github.com/imochen/hotcss 或者我的百度网盘:http://pan.baidu.com/s/1pKlLqHX 使用方法看demo ...