技术小黑屋

超简单实现Google+列表特效

相信用过Google+的人都感到其应用的特效相当棒,本文将以超简单的形式来实现类似Google+列表的特效。仅仅写几行代码就可以实现奥。

##特效真面目 由于众所周知的原因,很多人无法使用Google+应用。所以有必要让大家先看一看真面目。 P.S.找了很多的屏目录制软件都不行,并且没有4.4的机器,所以只能用最笨的方法录制了,请见谅哈。

##特效动画 ###from_bottom_to_top.xml

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:shareInterpolator="true">
    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="100%" android:toYDelta="0%"
        android:duration="400" />
</set>

###from_top_to_bottom.xml

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:shareInterpolator="true">
    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="-100%" android:toYDelta="0%"
        android:duration="400" />
</set>

##加入动画

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private int mLastPosition = -1;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	View view = super.getView(position, convertView, parent);
	int animResId;
	if (position > mLastPosition) {
		animResId = R.anim.from_bottom_to_top;
	} else {
		animResId = R.anim.from_top_to_bottom;
	}
			
	Animation animation = AnimationUtils.loadAnimation(getContext(), animResId);
	view.startAnimation(animation);
	mLastPosition = position;
	return view;
}

###其他





快来解锁最新版 Typora,新用户券后仅需 84 元!
如何便宜的购买 office 365 ?
新版赤友 NTFS 助手来袭,正版超低价