写在前面
这段时间由于找工作的原因,下载了boss直聘,在ios最新版(4.1)上点击首页列表进行页面跳转的那个效果感觉很炫,但是android最新版本(4.2)上却没有对应的效果,不知道以前版本有没有,感觉很好奇,所以就有了本文…
IOS版本boss直聘的效果
分析
通过多次观察页面跳转动画,发现其实现过程也很简单:
1、获取列表中item的位置。
2、把根布局缩放0.9倍,同时跳出悬浮框,添加一个View(暂且称它为tempView),设置tempView的高度和宽度为列表的item的高度和宽度。
3、对tempView进行缩放,缩放倍数为tempView距离屏幕顶部,距离屏幕底部中的最大值处于tempView高度: Math.max(tempView.locationX, Math.abs(tempView.locationX - ScreenHeight)) / tempView.height。
4、在安卓上,即使设置
Intent.FLAG_ACTIVITY_NO_ANIMATION
在部分机型上也无法禁止动画,如果按照正常的步骤,关闭悬浮框再进行页面跳转,就达不到boss直聘上的跳转效果,所以就需要当tempView展开到最大时,马上进行页面跳转。
5、启动加载等待动画,延时1秒后,启动alpha动画,将tempView透明度设置为0,关闭悬浮框。
悬浮框代码
public class BossTransferView extends LinearLayout {
private static final String TAG = "ExpansionTemp";
private View mHandleView;
private WindowManager mWm;
private ImageView mImg;
private View mTemp;
private ImageView mPb;
private int[] mLocation = new int[2];
private View mRootView;
public BossTransferView(Context context, View rootView, View handleView, WindowManager wm) {
super(context, null);
mHandleView = handleView;
mRootView = rootView;
mWm = wm;
init();
}
public BossTransferView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
}
public BossTransferView(Context context, AttributeSet attrs,