ObjectAnimator简单示例
<?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简单示例的更多相关文章
- Linux下的C Socket编程 -- server端的简单示例
Linux下的C Socket编程(三) server端的简单示例 经过前面的client端的学习,我们已经知道了如何创建socket,所以接下来就是去绑定他到具体的一个端口上面去. 绑定socket ...
- C# 构建XML(简单示例)
C# 构建XML的简单示例: var pars = new Dictionary<string, string> { {"url","https://www. ...
- 根据juery CSS点击一个标签弹出一个遮罩层的简单示例
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- ACEXML解析XML文件——简单示例程序
掌握了ACMXML库解析XML文件的方法后,下面来实现一个比较完整的程序. 定义基本结构 xml文件格式如下 <?xml version="1.0"?> <roo ...
- demo工程的清单文件及activity中api代码简单示例
第一步注册一个账户,并创建一个应用.获取app ID与 app Key. 第二步下载sdk 第三步新建工程,修改清单文件,导入相关的sdk文件及调用相应的api搞定. 3.1 修改清单文件,主要是加入 ...
- spring-servlet.xml简单示例
spring-servlet.xml简单示例 某个项目中的spring-servlet.xml 记下来以后研究用 <!-- springMVC简单配置 --> <?xml versi ...
- SignalR 简单示例
一.什么是 SignalR ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of add ...
- Web API 简单示例
一.RESTful和Web API Representational State Transfer (REST) is a software architecture style consisting ...
- XML引入多scheme文件约束简单示例
XML引入多scheme文件约束简单示例,用company.xsd和department.xsd来约束company.xml: company.xsd <?xml version="1 ...
随机推荐
- 常用实验报告LaTex 模板
目录 模板1-无首页有表格头 模板2-有首页 模板1-无首页有表格头 % -*- coding: utf-8 -*- \documentclass{article} \usepackage{listi ...
- 如何使用Feign构造多参数的请求
原文:http://www.itmuch.com/spring-cloud-sum/feign-multiple-params/ 本节来探讨如何使用Feign构造多参数的请求.笔者以GET及POST请 ...
- Dymola — 多学科系统仿真平台
Dymola 是法国Dassault Systems公司的多学科系统仿真平台,广泛应用于国内外汽车.工业.交通.能源等行业的系统总体架构设计.指标分解以及系统功能验证及优化等.Dymo ...
- 'Cloud Native': What It Means, Why It Matters
When HP announced July 28 that it was acquiring ActiveState's PaaS business, senior vice president B ...
- IntelliJ IDEA如何默认使用阿里云的Maven仓库
点击IntelliJ IDEA的config中的setting选项 在<mirrors>节点中加上一个子节点,然后保存即可: <mirror> <id>alimav ...
- Mac系统上,Firefox和Selenium不兼容的情况
解决办法,检查环境: Python 2.7.10 Firefox 46版本 Selenium 2.53.6 注意:将Firefox自动更新关闭,否则可能会出现自动升级以后无法执行Selenium用例的 ...
- [Dart] Understand Classes and Inheritance in Dart
We will look at how we can create classes and explore some various features. Dart adopts a single-in ...
- Greenplum 查看表的分区键与分区类型
方法一 查看表的分区键 select d.nspname||'.'||a.relname as table_name,string_agg(b.attname,',') as column_namef ...
- learning scala PartialFunction
Partial函数的定义 scala> val isVeryTasty: PartialFunction[String, String] = { case "Glazed Donut& ...
- The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest
目录 Contest Info Solutions A. Attack B. Polynomial E. Interesting Trip F. Sequence G. Winner H. Anoth ...