栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android Animation之TranslateAnimation(平移动画)

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android Animation之TranslateAnimation(平移动画)

TranslateAnimation(平移动画)的意思无非就是一张图片或其他从一个位置到达另外一个位置。直接代码分析,相关重要属性参数解释都在代码中。

1、首先编写main.xml文件。

 

   

 

2、接下来编写MainActivity.java文件。

package com.example.dell.bitmapproject; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.AnimationSet; 
import android.view.animation.TranslateAnimation; 
import android.widget.ImageView; 

public class MainActivity extends AppCompatActivity { 
  private ImageView image; 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    image =(ImageView)findViewById(R.id.image); 
    image.setonClickListener(new onClickListenerImpl()); 
  } 
  private class onClickListenerImpl implements View.onClickListener { 
    @Override 
    public void onClick(View v) { 
       

      AnimationSet animationSet = new AnimationSet(true); 
       
      TranslateAnimation translateAnimation = new TranslateAnimation( 
   //X轴初始位置 
   Animation.RELATIVE_TO_SELF, 0.0f, 
   //X轴移动的结束位置 
   Animation.RELATIVE_TO_SELF,0.5f, 
   //y轴开始位置 
   Animation.RELATIVE_TO_SELF,0.0f, 
   //y轴移动后的结束位置 
   Animation.RELATIVE_TO_SELF,1.5f); 

      //3秒完成动画 
      translateAnimation.setDuration(2000); 
      //如果fillAfter的值为真的话,动画结束后,控件停留在执行后的状态 
      animationSet.setFillAfter(true); 
      //将AlphaAnimation这个已经设置好的动画添加到 AnimationSet中 
      animationSet.addAnimation(translateAnimation); 
      //启动动画 
      MainActivity.this.image.startAnimation(animationSet); 

    } 
  } 
} 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/157731.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号