package com.loaderman.customviewdemo;

import android.animation.ObjectAnimator;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View; public class MainActivity extends AppCompatActivity {
private FallingBallImageView ball_img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // ball_img = (FallingBallImageView) findViewById(R.id.ball_img); findViewById(R.id.start_anim).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ObjectAnimator animator = ObjectAnimator.ofObject(ball_img, "fallingPos", new FallingBallEvaluator(), new Point(0, 0), new Point(500, 500));//set函数对于的属于应该是fallingPos或者FallingPos
animator.setDuration(2000);
animator.start();
}
});
}
}
package com.loaderman.customviewdemo;

import android.animation.TypeEvaluator;
import android.graphics.Point; public class FallingBallEvaluator implements TypeEvaluator<Point> {
private Point point = new Point();
public Point evaluate(float fraction, Point startValue, Point endValue) {
point.x = (int)(startValue.x + fraction *(endValue.x - startValue.x)); if (fraction*2<=1){
point.y = (int)(startValue.y + fraction*2*(endValue.y - startValue.y));
}else {
point.y = endValue.y;
}
return point;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
tools:context="com.loaderman.customviewdemo.MainActivity"> <com.loaderman.customviewdemo.FallingBallImageView
android:id="@+id/ball_img"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/cicle"/> <Button
android:id="@+id/start_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始动画"/> </LinearLayout>
package com.loaderman.customviewdemo;

import android.content.Context;
import android.graphics.Point;
import android.util.AttributeSet; public class FallingBallImageView extends android.support.v7.widget.AppCompatImageView {
public FallingBallImageView(Context context) {
super(context);
} public FallingBallImageView(Context context, AttributeSet attrs) {
super(context, attrs);
} public FallingBallImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} public void setFallingPos(Point pos){
layout(pos.x, pos.y, pos.x + getWidth(), pos.y + getHeight());
} }

自定义ObjectAnimator属性实现的更多相关文章

  1. 自定义Property属性动画

    同步发表于 http://avenwu.net/customlayout/2015/04/06/custom_property_animation/ 代码获取 git clone https://gi ...

  2. Android之探究viewGroup自定义子属性参数的获取流程

    通常会疑惑,当使用不同的布局方式时,子view得布局属性就不太一样,比如当父布局是LinearLayout时,子view就能有效的使用它的一些布局属性如layout_weight.weightSum. ...

  3. Android读取自定义View属性

    Android读取自定义View属性 attrs.xml : <?xml version="1.0" encoding="utf-8"?> < ...

  4. android自定义view属性

    第一种 /MainActivity/res/values/attrs.xml <?xml version="1.0" encoding="utf-8"?& ...

  5. html5的自定义data-*属性和jquery的data()方法的使用示例

    人们总喜欢往HTML标签上添加自定义属性来存储和操作数据. 但这样做的问题是,你不知道将来会不会有其它脚本把你的自定义属性给重置掉,此外,你这样做也会导致html语法上不符合Html规范,以及一些其它 ...

  6. 自定义 Layer 属性的动画

    默认情况下,CALayer 及其子类的绝大部分标准属性都可以执行动画,无论是添加一个 CAAnimation 到 Layer(显式动画),亦或是为属性指定一个动作然后修改它(隐式动画).   但有时候 ...

  7. Android自定义XML属性以及遇到的命名空间的问题

    转载请注明出处:http://www.cnblogs.com/kross/p/3458068.html 最近在做一些UI,很蠢很蠢的重复写了很多代码,比如一个自定义的UI Tab,由一个ImageVi ...

  8. android 自定义View属性

    在android开发过程中,用到系统的View时候可以通过XML来定义一些View的属性.比如ImageView:   android:src  和android:scaleType为ImageVie ...

  9. .net使用自定义类属性

    .net中可以使用Type.GetCustomAttributes获取类上的自定义属性,可以使用PropertyInfo.GetCustomAttributes获取属性信息上的自定义属性. 下面以定义 ...

随机推荐

  1. nginx基础概述

    为什么选择nginx     nginx非常轻量     互联网公司都选择nginx nginx技术成熟,具备的功能时企业最常用使用而且最需要的 适合当前主流架构趋势,微服务.云架构.中间层 统一技术 ...

  2. Java中实现图片的上传

    这边直接存放在c盘的指定目录,在property中指定了一个目录 没有花时间写用户操作的上传页面,直接用swagger2插件,可以上传 默认图片大小超过1mb就不可以上传,可以如下更改 server. ...

  3. C++中priority_queue的用法

    本来想自己写一写的,但看到这个随笔,感觉要写的东西跟这个差不多,就直接附上链接. 需要注意事项: rand()函数需要引入头文件#include<cstdlib>. 自定义类型,重载ope ...

  4. WinForm DevExpress使用之ChartControl控件绘制图表一——基础

    最近因为公司项目需要用到WinForm的DecExpress控件,在这里把一些使用方法总结一下. DevExpress中有一个专门用来绘制图表的插件ChartControl,可以绘制折线图.饼状图.柱 ...

  5. Java Redis+Spring-data-redis 队列 单机版

    1.redis.properties ##redisIP地址 #redis.host=10.14.2.212 redis.host=127.0.0.1 ##redis默认端口号 redis.port= ...

  6. mongodb 高级聚合查询

    mongodb高级聚合查询   在工作中会经常遇到一些mongodb的聚合操作,特此总结下.mongo存储的可以是复杂类型,比如数组.对象等mysql不善于处理的文档型结构,并且聚合的操作也比mysq ...

  7. learning scala How To Create Implicit Function

    println("Step 1: How to create a wrapper String class which will extend the String type") ...

  8. Educational Codeforces Round 75

    目录 Contest Info Solutions A. Broken Keyboard B. Binary Palindromes C. Minimize The Integer D. Salary ...

  9. centos7haproxy+keepalive

    1部署keepalived 1.1下载keepalived源码包,并解压# wget http://www.keepalived.org/software/keepalived-1.4.2.tar.g ...

  10. Java监听器listener的介绍

    Java监听器listener的介绍 listener 能做什么 当web中某些动作发生之后,服务器就调用listener中对应的方法. 内部机制 接口回调 Web监听器 步骤 创建需要的监听器类,实 ...