Android中属性动画3----ObjectAnimator实现一个动画菜单
来源:互联网 发布:首汽约车有抢单软件吗 编辑:程序博客网 时间:2024/05/21 05:21
效果图
代码:
Main3Activity中
package com.zhh.android;import android.animation.ObjectAnimator;import android.app.Activity;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.animation.BounceInterpolator;import android.widget.ImageView;import android.widget.Toast;import java.util.ArrayList;import java.util.List;/** * 利用ObjectAnimator * 实现一个菜单 */public class Main3Activity extends Activity implements View.OnClickListener { // 写一个存放图片的数组 private int[] imageArray = {R.id.imageViewA, R.id.imageViewB, R.id.imageViewC, R.id.imageViewD, R.id.imageViewE, R.id.imageViewF, R.id.imageViewG, R.id.imageViewH,}; private ArrayList<ImageView> imageViewArray = new ArrayList<>(); private boolean flag=true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); for (int i = 0; i < imageArray.length; i++) { ImageView imageView = (ImageView) findViewById(imageArray[i]); imageView.setOnClickListener(this); imageViewArray.add(imageView); } } @Override public void onClick(View v) { switch (v.getId()) { case R.id.imageViewA: if(flag) { startAnimator(); }else{ closeAnimator(); } break; default: Toast.makeText(Main3Activity.this, "点击事件"+v.getId(), Toast.LENGTH_SHORT).show(); startActivity(new Intent(Main3Activity.this,Main4Activity.class)); break; } } /** * 展开菜单 */ private void startAnimator(){ Log.e("111","startAnimator"); for(int i = 1; i <imageArray.length ; i++) { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageViewArray.get(i),"translationY",0F,i*200F); objectAnimator.setDuration(500); //有加速度(速度是不断增加的)有回弹效果 objectAnimator.setInterpolator(new BounceInterpolator()); objectAnimator.setStartDelay(i*300);//动画延时执行 objectAnimator.start(); } flag=false; } /** * 关闭菜单 */ private void closeAnimator(){ Log.e("111","closeAnimator"); for(int i = 1; i <imageArray.length ; i++) { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(imageViewArray.get(i),"translationY",i*200F,0F); objectAnimator.setDuration(500);// 有加速度(速度是不断增加的)有回弹效果 objectAnimator.setInterpolator(new BounceInterpolator()); objectAnimator.setStartDelay(i*300);//动画延时执行 objectAnimator.start(); } flag=true; }}activity_main3.xml
<?xml version="1.0" encoding="utf-8"?><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" tools:context="com.zhh.android.Main3Activity"> <ImageView android:id="@+id/imageViewB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/b" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewC" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/c" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewD" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/d" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewE" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/e" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewF" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/f" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewG" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/g" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewH" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/h" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/imageViewA" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/a" android:layout_centerHorizontal="true" /></RelativeLayout>参考视频:
http://www.imooc.com/learn/263源码下载:
http://download.csdn.net/download/zhaihaohao1/10126123
阅读全文
0 0
- Android中属性动画3----ObjectAnimator实现一个动画菜单
- Android动画-属性动画-ObjectAnimator
- android 动画 属性动画 ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- Android属性动画之ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- 【Android动画九章】-属性动画ObjectAnimator
- Android 动画之属性动画ObjectAnimator
- Android ObjectAnimator动画效果实现
- android属性动画效果的实现之ObjectAnimator
- Android中属性动画2----ObjectAnimator监听的使用
- 属性动画ObjectAnimator
- 属性动画之ObjectAnimator
- 属性动画之ObjectAnimator
- typedef的使用说明
- Got a packet bigger than \'max_allowed_packet\' bytes问题排除
- 【MySQL】查看MySQL配置文件路径及相关配置
- sbuf.st_size 为负数
- C语言 struct结构体的变量声明加冒号
- Android中属性动画3----ObjectAnimator实现一个动画菜单
- Linux操作系统中文件结构stat中st_size的说明以及对于文件中洞(Holes)的理解
- 线性表的顺序存储结构
- PHP读取BMP格式图片的函数
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
- 云相关各种单词说明
- 解析器与解释器
- sublime注册
- sublime汉化