Animator属性动画

主函数

import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.animation.BounceInterpolator;import android.widget.ImageView;import java.util.ArrayList;import java.util.List;public class MainActivity extends AppCompatActivity implements View.OnClickListener {    private Button button;    //判断是否弹出    private boolean flag = true;    //设置卫星菜单半径    private int radius = 500;    //定义菜单图标    private int[] res = new int[]{        R.id.id_img_a,R.id.id_img_b,R.id.id_img_c,R.id.id_img_d,R.id.id_img_e,R.id.id_img_f,R.id.id_img_g,R.id.id_img_h    };    //定义菜单列表    private List list = new ArrayList();    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //初始化菜单图标        for (int i = 0; i < res.length; i++) {            ImageView imageView = (ImageView) findViewById(res[i]);            imageView.setOnClickListener(this);            list.add(imageView);        }    }    /**     * 设置菜单点击事件     * @param view     */    @Override    public void onClick(View view) {        switch (view.getId()) {            case R.id.id_img_a:                if (flag) {                    startAnim();                    flag = false;                } else {                    closeAnim();                    flag = true;                }                break;            case R.id.id_img_b:                break;            case R.id.id_img_c:                break;            case R.id.id_img_d:                break;            case R.id.id_img_e:                break;            case R.id.id_img_f:                break;            case R.id.id_img_g:                break;            case R.id.id_img_h:                break;        }    }    /**     * 关闭菜单     */    private void closeAnim() {        for (int i = 1; i < res.length; i++) {            ObjectAnimator animator1 = ObjectAnimator.ofFloat(list.get(i), "translationX", (float)(radius*Math.cos((i-1)*Math.PI/12)), 0F);            ObjectAnimator animator2 = ObjectAnimator.ofFloat(list.get(i), "translationY", (float)(radius*Math.sin((i-1)*Math.PI/12)), 0F);            AnimatorSet set = new AnimatorSet();            set.playTogether(animator1, animator2);            set.setDuration(500);            set.start();        }    }    /**     * 弹出菜单     */    private void startAnim() {        for (int i = 1; i < res.length; i++) {            //设置x方向位移            ObjectAnimator animator1 = ObjectAnimator.ofFloat(list.get(i), "translationX", 0F, (float)(radius*Math.cos((i-1)*Math.PI/12)));            //设置y方向位移            ObjectAnimator animator2 = ObjectAnimator.ofFloat(list.get(i), "translationY", 0F, (float)(radius*Math.sin((i-1)*Math.PI/12)));            //初始化动画集合            AnimatorSet set = new AnimatorSet();            set.playTogether(animator1, animator2);            set.setDuration(500);            set.setInterpolator(new BounceInterpolator());            set.start();        }    }}

布局文件

<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.hpf.animatordemo.MainActivity">    <ImageView        android:id="@+id/id_img_b"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/b"/>    <ImageView        android:id="@+id/id_img_c"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/c"/>    <ImageView        android:id="@+id/id_img_d"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/d"/>    <ImageView        android:id="@+id/id_img_e"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/e"/>    <ImageView        android:id="@+id/id_img_f"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/f"/>    <ImageView        android:id="@+id/id_img_g"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/g"/>    <ImageView        android:id="@+id/id_img_h"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="7dp"        android:paddingTop="7dp"        android:src="@mipmap/h"/>    <ImageView        android:id="@+id/id_img_a"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:paddingLeft="5dp"        android:paddingTop="5dp"        android:src="@mipmap/a"/>FrameLayout>

Animation补间动画

稍后更新

更多相关文章

  1. 仿抖音视频详情页的红心点赞动效
  2. Universal Image Loader for Android(安卓)说明文档
  3. 安卓编译环境设置
  4. android+SurfaceView+path+onTouchEvent画图
  5. Android切换主题
  6. Android中关于setTitle(CharSequence title)的知识总结
  7. ListView继续学习 长按显示菜单menu
  8. WebView的使用(基本篇)
  9. Android(安卓)shape使用笔记

随机推荐

  1. [Android] [ANR的原理、分析、实战] 【转
  2. Android(安卓)Jetpack之Navigation
  3. Android之网络请求1————HTTP协议
  4. 通信之进程间通信-AIDL
  5. android aidl 使用实例
  6. [置顶] Android拼图游戏开发全纪录1
  7. Android常用权限permission列表摘录
  8. Win8/Android双系统 华硕Win8平板曝光
  9. 破了个新纪录
  10. Android Broadcast receiver使用入门