自定义ObjectAnimator属性实现
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属性实现的更多相关文章
- 自定义Property属性动画
同步发表于 http://avenwu.net/customlayout/2015/04/06/custom_property_animation/ 代码获取 git clone https://gi ...
- Android之探究viewGroup自定义子属性参数的获取流程
通常会疑惑,当使用不同的布局方式时,子view得布局属性就不太一样,比如当父布局是LinearLayout时,子view就能有效的使用它的一些布局属性如layout_weight.weightSum. ...
- Android读取自定义View属性
Android读取自定义View属性 attrs.xml : <?xml version="1.0" encoding="utf-8"?> < ...
- android自定义view属性
第一种 /MainActivity/res/values/attrs.xml <?xml version="1.0" encoding="utf-8"?& ...
- html5的自定义data-*属性和jquery的data()方法的使用示例
人们总喜欢往HTML标签上添加自定义属性来存储和操作数据. 但这样做的问题是,你不知道将来会不会有其它脚本把你的自定义属性给重置掉,此外,你这样做也会导致html语法上不符合Html规范,以及一些其它 ...
- 自定义 Layer 属性的动画
默认情况下,CALayer 及其子类的绝大部分标准属性都可以执行动画,无论是添加一个 CAAnimation 到 Layer(显式动画),亦或是为属性指定一个动作然后修改它(隐式动画). 但有时候 ...
- Android自定义XML属性以及遇到的命名空间的问题
转载请注明出处:http://www.cnblogs.com/kross/p/3458068.html 最近在做一些UI,很蠢很蠢的重复写了很多代码,比如一个自定义的UI Tab,由一个ImageVi ...
- android 自定义View属性
在android开发过程中,用到系统的View时候可以通过XML来定义一些View的属性.比如ImageView: android:src 和android:scaleType为ImageVie ...
- .net使用自定义类属性
.net中可以使用Type.GetCustomAttributes获取类上的自定义属性,可以使用PropertyInfo.GetCustomAttributes获取属性信息上的自定义属性. 下面以定义 ...
随机推荐
- 【问题】man手册如何查看区分printf命令和printf函数
参考:UNIX / Linux Man Command Example to View Man Pages 今天再看别人博客的时候,先仔细看看printf命令是怎么玩的,于是man手册查了下.结果搜出 ...
- ubuntu 修改环境变量(PATH)
1.什么是环境变量(PATH) 在Linux中,在执行命令时,系统会按照PATH的设置,去每个PATH定义的路径下搜索执行文件,先搜索到的文件先执行. 我们知道查阅文件属性的指令ls 完整文件名为:/ ...
- 【转】Python之可变参数,*参数,**参数,以及传入*参数,进行解包
https://blog.csdn.net/cadi2011/article/details/84871401 1.定义了一个需要两个参数的函数 def print_str(first, second ...
- linux使用文本编辑器vi常用命令
一:翻页 ctrl+u向上翻半页 ctrl+d 向下翻半页 ctrl+f/page up向上翻一页 ctrl+b/page on 向下翻一页 H光标移到当前页的第一个字符 M光标移到当前页的中 ...
- Herbert Schildt
赫伯特·希尔特; Herbert Schildt,是世界顶级程序设计大师,全球顶尖编程图书作者之一. www.HerbSchildt.com 1.c/c++的核心设计原理之一就是程序员的控制,java ...
- Winform工程反编译后的工作
Winform工程,反编译后,虽然能用,但不太好用. 因为form并没有像原生的那样. 所以,需要几个步聚: 1. 用ResGen工具,把二进制资源文件还原为xml格式: ResGen fromXX. ...
- P1273 有线电视网[分组背包+树形dp]
题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部节点. 从转播站到转播站以及从 ...
- Geohash 基本知识及 .NET 下计算相邻8个区域编码
目录 一.简介 二.计算方法 三.GeoHash的精度 四.查找相邻8个区域的Geohash编码(.NET) 五.MySQL 中使用 GeoHash 最近项目中需要搜索周边的 POI 信息,查找的过程 ...
- aiohttp 支持异步的网络请求模块
通常在进行网络数据采集时候我们会用到requests,urllib等模块,但是这些模块在使用中并不支持异步,所以今天我们介绍一个支持异步网络请求的模块aiohttp. 首先我们使用flask简单的搭一 ...
- python 操作 MySQL 即相关问题
导入pymysql import pymysql # 创建connect()对象 conn = pymysql.connect( host = '127.0.0.1', port = 3306, us ...