自定义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获取属性信息上的自定义属性. 下面以定义 ...
随机推荐
- Linux命令——column
参考:Viewing Linux output in columns 功能 column命令把他的输入格式化多列显示.输入可以是文件,也可以是标准输入. 列优先,从左到右 显示的时候首先填满最左列,然 ...
- 在Linux中安装适用于arm64位的nodejs
# 安装适用于arm64位的nodejs runtime v10.16.3 mkdir /runtimes cd /runtimes wget https://nodejs.org/dist/v10. ...
- roles
nginx 官方下载 [root@ansible roles]# tree yngx yngx ├── defaults ├── files │ ├── blog.conf │ ├── edu ...
- Python语言程序设计:Lab4
Programming 1.Analysing a Text File Look at the file xian_info.txt which is like this: Xi'an China 8 ...
- Dymola — 多学科系统仿真平台
Dymola 是法国Dassault Systems公司的多学科系统仿真平台,广泛应用于国内外汽车.工业.交通.能源等行业的系统总体架构设计.指标分解以及系统功能验证及优化等.Dymo ...
- Spring Boot 项目在 IntelliJ IDEA 中配置 DevTools 实现热部署(macOS 系统)
要配置的内容: 1.Preference -> Build, Execution, Deployment -> Complier -> Build project automatic ...
- 多继承以及MRO顺序
class A: def test(self): print("A --- test方法") def demo(self): print("A --- demo方法&qu ...
- 2019-2020-1 20199312《Linux内核原理与分析》第五周作业
使用库函数API获取当前时间 #include <stdio.h> #include <time.h> int main() { time_tt tt; struct tm * ...
- python 虚拟环境相关命令
1.总是记不住一些关于创建虚拟环境得命令,特在自己得博客里记录一下自己常用得命令: virtualenv -p C:\Python36\python D:\virtual\Envs\AssetScan ...
- 测试使用API
https://api.github.com/users/github 返回值中的某些URL也可以作为测试API使用