仿<赶集生活>client启动动画效果

yutingliuyl yutingliuyl     2022-08-27     645

关键词:

        demo下载地址: http://yun.baidu.com/s/1i3wqEMh


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


技术分享

//FeatureAnimationListener.java

package 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.java

package com.example.animatetest;

public abstract interface OnScrollChangedListener {
	public abstract void onScrollChanged(int top, int oldTop);
}

//ObservableScrollView.java

package 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.java

package 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的滑动状态,从而控制动画的显示和消失。









c++标准库stl——仿函数和适配器(代码片段)

仿函数functioncalloperator仿函数中的函数名,是一个operator()仿函数主要是用来服务算法的,如果要被算法调用就需要重载()。这里称这种()为functioncalloperator仿函数主要分为三大类:算术类template<classT>structplus:publicbin... 查看详情

stl——容器(set&multiset)之仿函数(函数对象)functor的用法(代码片段)

...或者从小到大排列,这个是怎么实现的?这就要说“仿函数”这个概念了。 仿函数概念1.尽管函数指针被广泛用于实现函数回调,但C++还提供了一个重要的实现回调函数的方法,那就是函数对象。2.functor,翻译成函数... 查看详情

c++解析命令行参数(仿c语言args)(代码片段)

说好不造轮子的,就管不住这手#include<cstdio>#include<string>#include<vector>boolParseChar(conststd::string&buf,std::size_t&pos,char&ch,bool&escape)charc;if(pos==buf.length())retur 查看详情

list仿函数

#include<algorithm>usingnamespacestd;typedefstruct{ char*name; intstuid; intage;}Student;/**************************/boolcmp(constStudent&stua,constStudent&stub){ returnstua.age>stub. 查看详情

p1328生活大爆炸版石头剪刀布(代码片段)

一道模拟题,20个if搞定#include<cstdio>usingnamespacestd;inta[202],b[202];intmain()intn,na,nb,sa=0,sb=0;scanf("%d%d%d",&n,&na,&nb);for(inti=0;i<na;i++)scanf("%d",&a[i]);for(inti=0;i<nb;i++)scanf("%d",&b[i]);for(inti=0;i<n;i++)if(a[i%na]==0&&b[i%nb]=... 查看详情

html中&lt;li&gt;&lt;/li&gt;中使用&lt;br&gt;和&lt;li&gt;&lt;/li&gt

</pre><pre><!DOCTYPEhtml><html><head> <metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"> <title>欢迎到訪</title> <style 查看详情

css3&javascript仿京东加入购物车特效(代码片段)

上一篇文章https://blog.csdn.net/chy555chy/article/details/85063189我简单的介绍了如何使用原生的JavaScript配合上正则表达式来实现模板引擎(template.js)的简化版。本文对基于上文的代码,对原代码进行了修改,利用flex实现... 查看详情

apachehttpcomponents工具类[httputil](代码片段)

pom.xml&lt;dependency&gt;&lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;&lt;artifactId&gt;httpclient&lt;/artifactId&gt;&lt;version&gt;4.5.5&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;&lt;groupId&gt;org.... 查看详情

heap堆

#pragmaonce#include<iostream>usingnamespacestd;#include<vector>template<classT>   //仿函数structLess{   booloperator()(constT&l,constT&r) //重载 查看详情

滑动div函数

ThisassumesHTMLthatlookslikethis:<pre><code>&lt;divid=&quot;containing_div&quot;&gt;&lt;divid=&quot;div_1&quot;style=&quot;background-color:red&quot;class=&quot;visible_div&quot;&gt;&lt;p&gt;TestContent1&lt;/p&gt;&lt;/di... 查看详情

xsspayload(大集合)

<script>alert(/xss/)</script><script>alert(&#38;XSS&#38;)</script><script>alert(&quot;XSS&quot;)</script>(代替被转义的“”)<INPUTtype="text"value='\\'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRI... 查看详情

利用|,&amp;,^,~,&lt;&lt;,&gt;&gt;&gt;写出高效艺术的代码

简单介绍:大家在阅读源代码的时候常常会看到一些比方以下这样特别难理解的代码。cancelEvent.setAction(MotionEvent.ACTION_CANCEL|(motionEvent.getActionIndex()<<MotionEvent.ACTION_POINTER_INDEX_SHIFT));order=((order)>>(INDEX_OFFSET- 查看详情

&lt;sub&gt;&lt;sup&gt;标签

今天无意中看到一个标签认为挺有意思的。平时用得好少。<sup><sub>上标签和下标签。感觉这个命名就是以bp来决定是上还是下。b是下。p是上哈哈,是不是非常有意思贴一段代码看看<html><body><p>Thistextcontains... 查看详情

vue插槽(代码片段)

...规范草案,将<slot>元素作为承载分发内容的出口。&lt;navigation-linkurl="/profile"&gt;YourProfile&lt;/navigation-link&gt;然后在<navigation-link>的模板中可能会写为:&lt;a:href="url"class="nav-link"&gt;&lt;slot&gt;&lt;/slot&... 查看详情

vue基础指令集锦(代码片段)

v-model双向绑定数据&lt;inputtype="text"v-model="msg"&gt;msg###v-on事件&lt;divid="box"&gt;&lt;buttonv-on:click="say"&gt;按钮&lt;/button&gt;&lt;button@click="say"&gt;按钮&lt;/button&gt;&lt... 查看详情

vue中解析转义字符

...一下返回的富文本内容,发现里边包含了展示转义字符&lt;pstyle=&quot;line-height:150%&quot;&gt;&lt;spanstyle=&quot;;font-family:宋体;line-height:150%;font-size:16px&quot;&gt;&lt;spanstyle=&quot;font-family:宋体&quot;&gt;口腔... 查看详情

vue条件渲染(代码片段)

v-if字符串模板中,我们可以像这样写一个条件块:#ifok&lt;h1&gt;&lt;/h1&gt;/if在Vue中,我们使用v-if指令实现同样的功能:&lt;h1v-if="ok"&gt;&lt;/h1&gt;也可以使用v-else添加一个else块:&lt;h1v-if="ok"&gt;yes&lt;/h1... 查看详情

&lt;二&gt;读&lt;&lt;大话设计模式&gt;&gt;之策略模式

      又和大家见面了。可以坚持写出第二篇文章真不错,好好加油。      <<大话设计模式>>解说策略模式是以商场收银软件程序开头的,那么问题来了。哪家商场收银软件强... 查看详情