xml代码块:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
    <ImageView
        android:id="@+id/img_animations"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/img1"/>
   
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#ff00ff"/>
   
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal"
        >
       
        <Button
            android:id="@+id/but1"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="旋转"
            android:textColor="#ff00ff"/>
       
        <Button
            android:id="@+id/but2"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="位移"
            android:textColor="#ff00ff"/>
       
        <Button
            android:id="@+id/but3"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="渐变"
            android:textColor="#ff00ff"/>
       
        <Button
            android:id="@+id/but4"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="缩放"
            android:textColor="#ff00ff"/>
       
    </LinearLayout>

</LinearLayout>

JAVA代码块:

package com.sumzom.animations;

import com.example.com.sumzom.teach.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * @author sumzom
 * QQ2356066132
 * tween动画基本使用方法
 * */
public class AnimationsTest extends Activity implements OnClickListener{

private Button but1,but2,but3,but4 = null;
 private ImageView img_animations = null;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.animations);
  
  initWithView();
  
  initWithLogic();
  
 }

private void initWithLogic() {
  // TODO Auto-generated method stub
  
 }

private void initWithView() {
  // TODO Auto-generated method stub
  but1 = (Button) findViewById(R.id.but1);
  but2 = (Button) findViewById(R.id.but2);
  but3= (Button) findViewById(R.id.but3);
  but4 = (Button) findViewById(R.id.but4);
  img_animations = (ImageView) findViewById(R.id.img_animations);
  
  but1.setOnClickListener(this);
  but2.setOnClickListener(this);
  but3.setOnClickListener(this);
  but4.setOnClickListener(this);
 }

@Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  switch (arg0.getId()) {
  case R.id.but1:
   but1();
   Toast.makeText(getApplicationContext(), "旋转",
     Toast.LENGTH_SHORT).show();
   
   break;
   
        case R.id.but2:
   but2();
         Toast.makeText(getApplicationContext(), "位移",
     Toast.LENGTH_SHORT).show();
         
   break;
   
        case R.id.but3:
   but3();
         Toast.makeText(getApplicationContext(), "渐变",
     Toast.LENGTH_SHORT).show();
         
   break;
   
        case R.id.but4:
   but4();
         Toast.makeText(getApplicationContext(), "缩放",
     Toast.LENGTH_SHORT).show();
         
   break;

default:
   break;
  }
 }

//缩放
 private void but4() {
  // fromX, toX, fromY, toY, pivotXType,
  //pivotXValue, pivotYType, pivotYValue)
  AnimationSet set = new AnimationSet(true);
  ScaleAnimation animation = new ScaleAnimation(
    0, 0.1f, 0, 0.5f, Animation.RELATIVE_TO_SELF,
    0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
  animation.setDuration(3000);
  set.addAnimation(animation);
  img_animations.startAnimation(set);
 }

/**
 * @author sumzom
 * QQ2356066132
 * tween动画基本使用方法
 * 渐变
 * */
 private void but3() {
  //fromAlpha, toAlpha起始背景透明度,结束透明度
  AnimationSet animationSet = new AnimationSet(true);
  AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0.2f);
  alphaAnimation.setDuration(5000);
  animationSet.addAnimation(alphaAnimation);
  img_animations.startAnimation(animationSet);
 }

//位移
 private void but2() {
  // TODO Auto-generated method stub
  /**
   * @author sumzom
         * QQ2356066132
         * tween动画基本使用方法
   * 1~2参数 fromXType fromXValue:起始位置X类型与值
   * 3~4参数 toXType toXValue:结束位置X类型与值
   * 5~6参数 fromYType fromYValue:起始位置Y类型与值
   * 7~8参数 toYType toYValue:结束位置Y类型与值
   * */
  AnimationSet set = new AnimationSet(true);
  TranslateAnimation TSAM = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF,
    0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF,
    0.5f);
  TSAM.setDuration(3000);
  set.addAnimation(TSAM);
  img_animations.startAnimation(set);
  
 }
 
 
 //旋转
 private void but1() {
  // TODO Auto-generated method stub
  AnimationSet set = new AnimationSet(true);
  /**
   * @author sumzom
         * QQ2356066132
         * tween动画基本使用方法
   * RotateAnimation:旋转动画
   * 参数一:fromDegrees,起始角度
   * 参数二:toDegrees,结束角度
   * 后四参数确定圆心是哪个
   * 参数三:pivotXType,X坐标类型
   * 参数四:pivotXValue,X值
   * 参数五:pivotYType,Y类型
   * 参数六:pivotYValue,Y值
   * */
  RotateAnimation animation = new RotateAnimation(0, 360,
    Animation.RELATIVE_TO_SELF, 0.5f,
      Animation.RELATIVE_TO_SELF, 0.5f);
  
  animation.setDuration(3000);
  set.addAnimation(animation);
  img_animations.startAnimation(set);
  
 }
 
}

运行效果:

 
 
 
 
 
 
 
 

安卓开发基础之tween动画基本使用,代码教学的更多相关文章

  1. android安卓开发基础小笔记,添加按钮事件,打开新窗体,窗体传值,回传

    给一个按钮添加onclick事件 //获取按钮对象 Button Aiyo = (Button)findViewById(R.id.button1); Aiyo.setOnClickListener( ...

  2. 安卓开发学习历程1——《第一行代码》coolweather项目setOnItemClickListener函数,Sql语句修改对模拟app程序机影响

    今天,将<第一行代码>最后实战的coolweather项目,认真做了一遍. 今晚,在书中第一阶段开发代码认眞在Android studio敲完,发现setOnItemClickListen ...

  3. Web前端开发基础 第四课(盒代码模型)

    盒模型代码简写 还记得在讲盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左.具体应用在margin和paddin ...

  4. Eclipse安卓开发环境搭建

    前提,Java SDK和Eclipse搭建完毕 下载android SDK并安装 (官网:http://sdk.android-studio.org/ ) 找到安装目录,运行“SDK Manager. ...

  5. iOS开发基础-九宫格坐标(6)

    继续对iOS开发基础-九宫格坐标(5)中的代码进行优化. 优化思路:把字典转模型部分的数据处理操作也拿到模型类中去实现,即将 ViewController 类实现中 apps 方法搬到 WJQAppI ...

  6. Android(安卓)开发通过NDK调用JNI,使用opencv做本地c++代码开发配置方法 边缘检测 范例代码

    以前写过两个Android开发配置文档,使用NDK进行JNI开发,这样能够利用以前已经写好的C++代码. 前两篇博客地址: http://blog.csdn.net/watkinsong/articl ...

  7. Android基础夯实--重温动画(一)之Tween Animation

    心灵鸡汤:真正成功的人生,不在于成就的大小,而在于你是否努力地去实现自我,喊出自己的声音,走出属于自己的道路. 摘要 不积跬步,无以至千里:不积小流,无以成江海.学习任何东西我们都离不开扎实的基础知识 ...

  8. iOS开发UI篇—核心动画(基础动画)

    转自:http://www.cnblogs.com/wendingding/p/3801157.html 文顶顶 最怕你一生碌碌无为 还安慰自己平凡可贵 iOS开发UI篇—核心动画(基础动画) iOS ...

  9. 安卓开发_浅谈Android动画(四)

    Property动画 概念:属性动画,即通过改变对象属性的动画. 特点:属性动画真正改变了一个UI控件,包括其事件触发焦点的位置 一.重要的动画类及属性值: 1.  ValueAnimator 基本属 ...

随机推荐

  1. Web API应用架构在Winform混合框架中的应用(5)--系统级别字典和公司级别字典并存的处理方式

    在我这个系列中,我主要以我正在开发的云会员管理系统为例进行介绍Web API的应用,由于云会员的数据设计是支持多个商家公司,而每个公司又可以包含多个店铺的,因此一些字典型的数据需要考虑这方面的不同.如 ...

  2. 能分组的GridView

    有天在想工作上的事的时候,看着.net原有的DataGridView,想起以前我写过的一篇文章,总结了一个好的Gird控件应该具备哪些功能,在那里我提及到了分组功能,就像jqGrid那样, 其实这样的 ...

  3. 介绍开源的.net通信框架NetworkComms框架 源码分析(十六 ) ConnectionStatic

    原文网址: http://www.cnblogs.com/csdev Networkcomms 是一款C# 语言编写的TCP/UDP通信框架  作者是英国人  以前是收费的 目前作者已经开源  许可是 ...

  4. SSH实例(5)

    在src中新建struts.xml文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...

  5. pymssql examples

    http://pymssql.org/en/latest/pymssql_examples.html Example scripts using pymssql module. Basic featu ...

  6. 以Unix之名

    即便有了MBP,有时,还是想把MBP装上一个Linux发行版,因为习惯了Linux下的折腾. 但每次想要动手安装时,都会告诉自己,MacOS是很纯正的Unix系统,这样,内心的冲动就可以再多压一压. ...

  7. 《Java4Android》视频学习笔记——抽象类和抽象函数

    抽象函数的语法特征 1.类是抽象的,对象是具体的.面向对象里面有个非常重要的特征:先抽象,后具体. 2.只有函数的定义,而没有函数体的函数叫做抽象函数. abstract void fun(); ( ...

  8. 初识 PHPunit stub 模拟返回数据

    这是这段时间以来结合 PHPunit 文档和大牛们的讲解,想记录下自己学习到的知识,未来参考补充,完善学到的东西 我们一般使用单测对公司业务里的代码进行测试,他会帮忙找到你的一个个小小的思考不够全面的 ...

  9. Java异常的中断和恢复

    中断:抛出一个异常类的实例而终止现有程序的执行:恢复:不是抛出一个异常类的实例,而是调用一个用于解决问题的方法或就地解决问题. 在Java中,对那些要调用方法的客户程序员,我们要通知他们可能从自己的方 ...

  10. GJM : 使用浏览器的计算力,对抗密码破解 [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...