博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
仿<赶集生活>client启动动画效果
阅读量:6148 次
发布时间:2019-06-21

本文共 3991 字,大约阅读时间需要 13 分钟。

        demo下载地址: 

        由于前几年csdn泄露password的事件,导致我的账号被拿去发广告文章了,联系了管理员帮我把几篇广告文删掉,可是那几篇高质量的文章就这样没了。如今补回当中一篇。是关于怎样实现像赶集生活client第一次启动时的介绍动画的,demo在上面,能够下载来试试效果。有须要的能够在评论里提供邮箱。博主会把project发过去 : )

//FeatureAnimationListener.javapackage com.example.animatetest;import android.view.View;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;public class FeatureAnimationListener implements AnimationListener {	private View mAnimView;	private boolean mAnimIn;		public FeatureAnimationListener(View animView, boolean animIn) {		mAnimView = animView;		mAnimIn = animIn;	}	@Override	public void onAnimationEnd(Animation animation) {		if(!mAnimIn) {			mAnimView.setVisibility(View.INVISIBLE);		}	}	@Override	public void onAnimationRepeat(Animation animation) {}	@Override	public void onAnimationStart(Animation animation) {		if(mAnimIn) {			mAnimView.setVisibility(View.VISIBLE);		}	}}
//OnScrollChangedListener.javapackage com.example.animatetest;public abstract interface OnScrollChangedListener {	public abstract void onScrollChanged(int top, int oldTop);}
//ObservableScrollView.javapackage com.example.animatetest;import android.content.Context;import android.util.AttributeSet;import android.widget.ScrollView;public class ObservableScrollView extends ScrollView {	private OnScrollChangedListener onScrollChangedListener;	public ObservableScrollView(Context context, AttributeSet attrs,			int defStyle) {		super(context, attrs, defStyle);	}	public ObservableScrollView(Context context, AttributeSet attrs) {		super(context, attrs);	}	public ObservableScrollView(Context context) {		super(context);	}		@Override	protected void onScrollChanged(int l, int t, int oldl, int oldt) {		super.onScrollChanged(l, t, oldl, oldt);		if(this.onScrollChangedListener != null) {			onScrollChangedListener.onScrollChanged(t, oldt);		}	}	public void setOnScrollChangedListener(OnScrollChangedListener onScrollChangedListener) {		this.onScrollChangedListener = onScrollChangedListener;	}}
//MainActivity.javapackage com.example.animatetest;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.ViewTreeObserver.OnGlobalLayoutListener;import android.view.animation.Animation;import android.view.animation.AnimationUtils;public class MainActivity extends Activity implements OnGlobalLayoutListener, OnScrollChangedListener {	private ObservableScrollView mScrollView;	private View mAnimView;	private int mScrollViewHeight;	private int mStartAnimateTop;		@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.activity_main);				mScrollView = (ObservableScrollView)this.findViewById(R.id.scrollView1);		mScrollView.getViewTreeObserver().addOnGlobalLayoutListener(this);		mScrollView.setOnScrollChangedListener(this);				mAnimView = this.findViewById(R.id.anim1);		mAnimView.setVisibility(View.INVISIBLE);	}	@Override	public boolean onCreateOptionsMenu(Menu menu) {		getMenuInflater().inflate(R.menu.main, menu);		return true;	}	@Override	public void onGlobalLayout() {		mScrollViewHeight = mScrollView.getHeight();		mStartAnimateTop = mScrollViewHeight / 3 * 2;	}	boolean hasStart = false;	@Override	public void onScrollChanged(int top, int oldTop) {		int animTop = mAnimView.getTop() - top;				if(top > oldTop) {			if(animTop < mStartAnimateTop && !hasStart) {				Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.feature_anim2scale_in);				anim1.setAnimationListener(new FeatureAnimationListener(mAnimView, true));								mAnimView.startAnimation(anim1);				hasStart = true;			}		} else {			if(animTop > mStartAnimateTop && hasStart) {				Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.feature_alpha_out);				anim1.setAnimationListener(new FeatureAnimationListener(mAnimView, false));								mAnimView.startAnimation(anim1);				hasStart = false;			}		}	}}

        这里主要是继承ScrollView,重载里面的onScrollChanged方法。监听ScrollView的滑动状态,从而控制动画的显示和消失。

你可能感兴趣的文章
浅析LUA中游戏脚本语言之魔兽世界
查看>>
飞翔的秘密
查看>>
Red Hat 安装源包出错 Package xxx.rpm is not signed
查看>>
编译安装mysql-5.6.16.tar.gz
查看>>
类与成员变量,成员方法的测试
查看>>
活在当下
查看>>
每天进步一点----- MediaPlayer
查看>>
PowerDesigner中CDM和PDM如何定义外键关系
查看>>
跨域-学习笔记
查看>>
the assignment of reading paper
查看>>
android apk 逆向中常用工具一览
查看>>
MyEclipse 报错 Errors running builder 'JavaScript Validator' on project......
查看>>
Skip List——跳表,一个高效的索引技术
查看>>
Yii2单元测试初探
查看>>
五、字典
查看>>
前端js之JavaScript
查看>>
Log4J日志配置详解
查看>>
实验7 BindService模拟通信
查看>>
scanf
查看>>
Socket编程注意接收缓冲区大小
查看>>