简单位移动画TranslateAnimation

系统 1821 0
已不再推荐补间动画,请使用属性动画;
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


简单位移动画TranslateAnimation

每次点击往前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

简单循环动画的实现:
简单位移动画TranslateAnimation

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

  

简单位移动画TranslateAnimation


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论