`

简单位移动画TranslateAnimation

阅读更多
已不再推荐补间动画,请使用属性动画;
http://blog.csdn.net/guolin_blog/article/details/43536355
http://blog.csdn.net/guolin_blog/article/details/43816093


动画中的View的点击判断
http://blog.csdn.net/seker_xinjian/article/details/7236945
Android 动画框架详解
http://www.ibm.com/developerworks/cn/opensource/os-cn-android-anmt1/index.html




每次点击往前100或往后100.

package com.ql.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class App extends Activity {
	private Button btn_0,btn_1;
	private ImageView iv;
	private int count;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        iv = (ImageView)findViewById(R.id.iv);
        iv.bringToFront();
        btn_0=(Button)findViewById(R.id.btn_0);
        btn_0.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				TranslateAnimation animation = new TranslateAnimation(count*100, 100+count*100, 0, 0);
				animation.setInterpolator(new LinearInterpolator());
				animation.setDuration(400);
				animation.setFillAfter(true);
				iv.startAnimation(animation);
				count++;
			}
		});
        
        btn_1=(Button)findViewById(R.id.btn_1);
        btn_1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				TranslateAnimation animation = new TranslateAnimation(count*100, -100+count*100, 0, 0);
				animation.setInterpolator(new LinearInterpolator());
				animation.setDuration(400);
				animation.setFillAfter(true);
				iv.startAnimation(animation);
				count--;
			}
		});
        
        
    }
}


android 自定义Animation
http://lipeng88213.iteye.com/blog/1199120
http://www.ophonesdn.com/article/show/185

简单循环动画的实现:


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
	<alpha
		android:interpolator="@android:anim/linear_interpolator" 
		android:fromAlpha="1.0"
		android:toAlpha="0.1"
		android:duration="2000"
		android:repeatCount="infinite"
		android:repeatMode="reverse"
		/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator">
	<translate 
	android:fromXDelta="0" 
	android:toXDelta="100%" 
	android:duration="2000"
	android:repeatCount="infinite"
	android:repeatMode="reverse"
	/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<scale 
	    android:fromXScale="1.0" 
	    android:toXScale="2.0"
		android:fromYScale="1.0" 
		android:toYScale="2.0" 
		android:pivotX="50%"
		android:pivotY="50%" 
		android:duration="2000" 
		android:repeatCount="infinite"
		android:repeatMode="reverse"
		android:interpolator="@android:anim/linear_interpolator" 
		/>
</set>

使用:
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

public class App extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Animation alpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
        Animation translate = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
        Animation scale = AnimationUtils.loadAnimation(this, R.anim.anim_scale);
        
        TextView tv=(TextView)findViewById(R.id.tv);
        tv.startAnimation(alpha);
        ImageView iv0=(ImageView)findViewById(R.id.iv0);
        ImageView iv1=(ImageView)findViewById(R.id.iv1);
        ImageView iv2=(ImageView)findViewById(R.id.iv2);
        iv0.startAnimation(alpha);
        iv1.startAnimation(translate);
        iv2.startAnimation(scale);
        
    }
}
  • 大小: 64 KB
  • 大小: 18.6 KB
分享到:
评论
4 楼 hualikejava 2013-05-07  
如果有能介绍下AnimationSet TranslateAnimation更好,
3 楼 hubenshan 2012-11-29  
kankan
2 楼 wangpeifeng669 2012-08-01  
多谢。。前辈的文章都不错
1 楼 进阶兄 2011-09-06  
多谢,但凡觉得有用的,都支持一下

相关推荐

    Android 动画之TranslateAnimation应用详解

    android中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画效果 TranslateAnimation 位移动画效果 RotateAnimation 旋转动画效果 本节讲解TranslateAnimation动画,TranslateAnimation比较...

    Android Animation之TranslateAnimation(平移动画)

    详情请见博客:https://blog.csdn.net/qq_20785431/article/details/101199524

    Android补间动画基本使用(位移、缩放、旋转、透明)

    本文讲述了Android补间动画基本使用(位移、缩放、旋转、透明)。...//创建为位移动画对象,设置动画的初始位置和结束位置 TranslateAnimation ta = new TranslateAnimation(10, 150, 20, 140); 1. x坐标的起点位

    羽哥android动画-旋转+透明的血轮眼

    android动画 AlphaAnimation(透明度动画效果 );RotateAnimation(旋转动画效果);ScaleAnimation(缩放动画效果 ); TranslateAnimation(位移动画效果 )

    羽哥位移的血轮眼

    Android系统提供了4种动画效果,分别是: AlphaAnimation(透明度动画效果 );RotateAnimation(旋转动画效果);ScaleAnimation(缩放动画效果 ); TranslateAnimation(位移动画效果 )

    Android动画之补间动画用法最全详解

    本文目录补间动画概述和分类各类补间动画实现xml实现补间动画透明度动画-AlphaAnimation缩放动画-ScaleAnimation位移动画-TranslateAnimation旋转动画-RotateAnimation动画组合-AnimationSet代码实现补间动画透明度...

    android 补间动画(Tween Animation)和Frame Animation(帧动画)简单使用

    包含AlphaAnimation渐变效果... TranslateAnimation:位移渐变 ScaleAnimation:缩放渐变 RotateAnimation:旋转渐变 AnimationSet:组合渐变 frameAnimation:帧动画的xml和代码实现方式,非常适合新手朋友参考。

    viewpager的下横线指示器

    viewpager的下横线指示器,使用translateAnimation位移动画实现被选中页卡的下横线的移动

    Android 动画之ScaleAnimation应用详解

    android中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画效果 TranslateAnimation 位移动画效果 RotateAnimation 旋转动画效果 本节讲解ScaleAnimation 动画, ScaleAnimation(float fromX...

    Android 动画之AlphaAnimation应用详解

    android中提供了4中动画: AlphaAnimation 透明度动画效果 ScaleAnimation 缩放动画效果 TranslateAnimation 位移动画效果 RotateAnimation 旋转动画效果 本节讲解AlphaAnimation 动画,窗口的动画效果,淡入淡出...

    Android开发之图形图像与动画(二)Animation实现图像的渐变/缩放/位移/旋转

    主要类: Animation 动画 AlphaAnimation 渐变透明度 RotateAnimation 画面旋转 ScaleAnimation 渐变尺寸缩放 TranslateAnimation 位置移动 AnimationSet 动画集 一.AlphaAnimation 其中AlphaAnimation类第一个参数...

    viewpager实现页面导航之三

    新特点是使用translateAnimation位移动画实现被选中的点的移动。而不是用以往的方法实现点的切换。之所以说是点的移动而不是点的切换是因为,运行代码滑动页面时真的可以看到像在Flash中绿点的移动效果。以往的方法...

    ViewPagerFragment滑动切换

    //单个水平动画位移 private int two; private int three; private FragmentManager fragmentManager; private int displayWidth, displayHeight; @Override public void onCreate(Bundle savedInstanceState...

    android顶部滑动导航

    //执行位移动画 sayit_lines.startAnimation(animation); viewPager.setCurrentItem(checkedId); //ViewPager 跟随一起 切换 //记录当前 下标的距最左侧的 距离 tageDistance = (...

Global site tag (gtag.js) - Google Analytics