动画之补间缩放动画




第一步:在res中创建一个anim目录

第二步:在anim目录中创建XML文件(scale.xml,设置属性。不要忘了设置xmlns:。。。。,属性为oneshot,设置动画是否是循环播放,默认值为true

第三步:在主函数中创建animation对象,并用AnimationUtils.loadAnimationthisR.anim.scale);方法为animation对象添加动画效果。

第四步:在你所设定的图像视图中添加animation对象。

缩放动画中的属性介绍:

       android:interpolator//用于控制动画的变化速度,使得动画效果可以匀速、加速、减速或抛物线速度等各种速度变化
       android:fromXScale//用于指定动画开始时水平方向上的缩放系数,值为1.0表示不变化  
       android:toXScale//用于指定动画结束时水平方向上的缩放系数,值为1.0表示不变化 
       android:fromYScale//用于指定动画开始时垂直方向上的缩放系数,值为1.0表示不变化 
       android:toYScale//用于指定动画结束时垂直方向上的缩放系数,值为1.0表示不变化
       android:pivotX//用于指定轴心点x轴的坐标
       android:pivotY//用于指定轴心点y轴的坐标
       android:repeatMode//用于设置动画的重复方式,可选值为reverse(反向)或restart(重新开始)
       android:repeatCount//用于设置动画的重复次数,属性可以是代表次数的数值,也可以是infinite(无限循环)
       android:duration//用于指定动画的持续时间,单位为毫秒

具体操作:

1、在drawable添加1张图片,即需要循环播放的图片

lm1:

2、添加anim文件夹,在anim添加scale.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
         android:oneshot="true">
     <scale 
         android:fromXScale="0.5"
         android:fromYScale="0.5"
         android:toXScale="2.5"
         android:toYScale="2.5"
         android:pivotX="50%"
         android:pivotY="50%"
         android:repeatMode="restart"
         android:repeatCount="infinite"
         android:duration="2000"/>
</set>

3、布局文件activity_main

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

  <Button 
      android:id="@+id/translate"
      android:layout_width="60dp"
      android:layout_height="60dp"
      android:text="缩放"/>
  <ImageView 
      android:id="@+id/im"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:src="@drawable/lm1"
      android:layout_below="@id/translate"/>
</RelativeLayout>

4、MainActivity.java

package com.example.bujian;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
Button button;
ImageView imageview;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		button=(Button) findViewById(R.id.translate);
		imageview=(ImageView) findViewById(R.id.im);
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
			
				Animation animation=AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale);//创建animation对象,
				imageview.startAnimation(animation);//为控件添加动画效果
			}
		});		
	}
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值