<?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;
}
}

效果:

最新文章

  1. angluarjs2项目生成内容合并到asp.net mvc4项目中一起发布
  2. C#需知--长度可变参数--Params
  3. c#Dictionary键值对的使用
  4. 基于 jQuery 实现的精致作品集图片导航效果
  5. springMVC-1
  6. 最小生成树Prim算法(邻接矩阵和邻接表)
  7. paper 6:支持向量机系列三:Kernel —— 介绍核方法,并由此将支持向量机推广到非线性的情况。
  8. UI:页面传值、单例模式传值、属性传值、NSUserDefaults 数据持久化
  9. win7环境下配置Java环境
  10. 一 VC2008环境中ICE的配置
  11. xdu_1165:均值滤波
  12. Python 学习之路
  13. Hibernate学习笔记三 多表
  14. [C#]设计模式-简单工厂-创建型模式
  15. 在CentOS 7+ 安装Kubernetes入门(单Master)
  16. Selenium3 + Python3自动化测试系列一——安装Python+selenium及selenium3 浏览器驱动
  17. 个人作业-Week1(新增详细说明)
  18. LigerUi中为Grid表加上序号,并调整适当宽度!(实例)
  19. 转 Apache Kafka:下一代分布式消息系统
  20. 二叉树(前序,中序,后序,层序)遍历递归与循环的python实现

热门文章

  1. DDD总览
  2. 锁、threading.local、线程池
  3. LOJ-1308-Ant network(蚂蚁的网络)-求割点分隔开的子图个数及乘积
  4. puppeteer报错 UnhandledPromiseRejectionWarning: Error: Protocol error (Page.getLayoutMetrics): Target closed.
  5. JQgrid处理json数据
  6. mysqlcheck(MyISAM表维护工具)
  7. Spark RDD 到 LabelPoint的转换(包含构造临时数据的方法)
  8. list获取所有上级
  9. sql server update 的批量更新方法
  10. 洛谷 P2119 魔法阵 题解