<?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"> <TableLayout
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> <TableRow> <Button
android:id="@+id/start_alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="alpha"/> <Button
android:id="@+id/start_rotation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rotation"/> <Button
android:id="@+id/start_rotationX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rotationX"/> </TableRow> <TableRow> <Button
android:id="@+id/start_rotationY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rotationY"/> <Button
android:id="@+id/start_translationX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="translationX"/> <Button
android:id="@+id/start_translationY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="translationY"/>
</TableRow> <TableRow> <Button
android:id="@+id/start_scaleX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scaleX"/> <Button
android:id="@+id/start_scaleY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scaleY"/> </TableRow>
</TableLayout> <TextView
android:visibility="gone"
android:id="@+id/tv"
android:layout_marginLeft="30dp"
android:layout_width="50dp"
android:layout_height="20dp"
android:gravity="center"
android:text="启舰"
android:layout_marginTop="100dp"
android:layout_gravity="center"
android:background="#000000"
android:textColor="#ffffff"/> <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <Button
android:id="@+id/demobtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start anim"/> <com.loaderman.customviewdemo.CustomTextView
android:id="@+id/customtv"
android:layout_toRightOf="@id/demobtn"
android:layout_marginLeft="30dp"
android:layout_width="50dp"
android:layout_height="20dp"
android:gravity="center"
android:text="Hello"
android:background="#000000"
android:textColor="#ffffff"/> </RelativeLayout> </LinearLayout>
package com.loaderman.customviewdemo;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView; public class MainActivity extends AppCompatActivity {
private TextView tv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final CustomTextView tv2 = (CustomTextView) findViewById(R.id.customtv);
findViewById(R.id.demobtn).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ObjectAnimator animator = ObjectAnimator.ofFloat(tv2, "ScaleSize", 6);
animator.setDuration(2000);
animator.start();
}
}); tv = (TextView) findViewById(R.id.tv); findViewById(R.id.start_alpha).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* 实现alpha值变化
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "alpha", 1, 0, 1);
animator.setDuration(2000);
animator.start();
}
}); findViewById(R.id.start_rotation).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* Z轴旋转
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "rotation", 0, 270, 0);
animator.setDuration(2000);
animator.start();
}
}); findViewById(R.id.start_rotationX).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* RotationX旋转
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "rotationX", 0, 270, 0);
animator.setDuration(2000);
animator.start();
}
}); findViewById(R.id.start_rotationY).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* RotationY 旋转
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "rotationY", 0, 180, 0);
animator.setDuration(2000);
animator.start(); }
}); findViewById(R.id.start_translationX).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* translationX动画
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "translationX", 0, 200, -200, 0);
animator.setDuration(2000);
animator.start();
}
}); findViewById(R.id.start_translationY).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* translationY动画
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "translationY", 0, 200, -100, 0);
animator.setDuration(2000);
animator.start();
}
}); findViewById(R.id.start_scaleX).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/**
* scaleX缩放动画
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "scaleX", 0, 3, 1);
animator.setDuration(2000);
animator.start();
}
}); findViewById(R.id.start_scaleY).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { /**
* scaleY缩放动画
*/
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "scaleY", 0, 3, 1);
animator.setDuration(2000);
animator.start();
}
});
}
}
package com.loaderman.customviewdemo;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView; public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
} public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
} public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} public void setScaleSize(float num){
setScaleX(num);
} public float getScaleSize(){
return 0.5f;
}
}

效果:

ObjectAnimator简单示例的更多相关文章

  1. Linux下的C Socket编程 -- server端的简单示例

    Linux下的C Socket编程(三) server端的简单示例 经过前面的client端的学习,我们已经知道了如何创建socket,所以接下来就是去绑定他到具体的一个端口上面去. 绑定socket ...

  2. C# 构建XML(简单示例)

    C# 构建XML的简单示例: var pars = new Dictionary<string, string> { {"url","https://www. ...

  3. 根据juery CSS点击一个标签弹出一个遮罩层的简单示例

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  4. ACEXML解析XML文件——简单示例程序

    掌握了ACMXML库解析XML文件的方法后,下面来实现一个比较完整的程序. 定义基本结构 xml文件格式如下 <?xml version="1.0"?> <roo ...

  5. demo工程的清单文件及activity中api代码简单示例

    第一步注册一个账户,并创建一个应用.获取app ID与 app Key. 第二步下载sdk 第三步新建工程,修改清单文件,导入相关的sdk文件及调用相应的api搞定. 3.1 修改清单文件,主要是加入 ...

  6. spring-servlet.xml简单示例

    spring-servlet.xml简单示例 某个项目中的spring-servlet.xml 记下来以后研究用 <!-- springMVC简单配置 --> <?xml versi ...

  7. SignalR 简单示例

    一.什么是 SignalR ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of add ...

  8. Web API 简单示例

    一.RESTful和Web API Representational State Transfer (REST) is a software architecture style consisting ...

  9. XML引入多scheme文件约束简单示例

    XML引入多scheme文件约束简单示例,用company.xsd和department.xsd来约束company.xml: company.xsd <?xml version="1 ...

随机推荐

  1. 13. 请看TED 的演讲, 谈谈你对压力的看法,以及怎么和别人合作, 帮助别人,把压力转化为动力,在互相帮助的环境中成长。------------答题者:徐潇瑞

    看了ted的演讲,我觉得压力就像一根弹簧,有多大的压力,它就有多大的弹力:现实中只要你学会用一种永远不服输的顽强精神,去对待人生和社会中遇到的一切困难与挫折,宠辱不惊的看云卷云舒,悟潮起潮落.可是存在 ...

  2. python listdir() 中文路径 中文文件夹 乱码 解决方法

    python listdir() 中文路径 中文文件夹 乱码 解决方法 listdir(path)返回的结果的编码似乎和我们提供的 path 参数的编码有关: path = 'd:/test' try ...

  3. Java锁--Semaphore

    转载请注明出处:http://www.cnblogs.com/skywang12345/p/3534050.html Semaphore简介 Semaphore是一个计数信号量,它的本质是一个&quo ...

  4. js+css 动效+1的效果

    点击数值 +1 的动效 vue data:{ timer: null,plus:''// 次数 } method:{ animate(plus) { var _this = this; clearIn ...

  5. java上传1t文件

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用.此控件PC全平台支持包括mac,linux系统的文件上传,文章末尾将附上控件下载与教程链接 ...

  6. 关于 js 函数参数的this

    先看一道面试题: var number = 10; function fn() { console.log(this.number); } var obj = { number: 2, show: f ...

  7. PAT TOP 1005 Programming Pattern (35 分)哈希做法

    1005 Programming Pattern (35 分) Programmers often have a preference among program constructs. For ex ...

  8. [luogu] zpl的数学题1

    https://www.luogu.org/problemnew/show/U16887 $f[1] + f[2] + f[3] + .... + f[n] = f[n + 2] - 1$ 矩阵快速幂 ...

  9. SpatialHadoop的编译与运行

    本文通过MetaWeblog自动发布,原文及更新链接:https://extendswind.top/posts/technical/spatialhadoop_compile_and_run Spa ...

  10. python threading多线程

    import threading import time def print_time(threadName, delay, iterations): start = int(time.time()) ...