原来PATH的菜单效果如此简单。布局+TranslateAnimation搞定 and 高仿小米launcher(ZAKER)跨屏拖动item 02-29最新更新

2280人阅读 评论(0) 收藏 举报

 

http://www.eoeandroid.com/thread-157511-1-1.html


提取了下PATH的菜单的那种动画效果。先看贴图
1.png 

源码:  PathMenu.zip (1.3 MB, 下载次数: 466) 
效果APK:  PathMenu.apk (466.77 KB, 下载次数: 57) 

原理:
点击红色加号触发事件:

  1. public static void startAnimationsIn(ViewGroup viewgroup,int durationMillis) {
  2.   for (int i = 0; i < viewgroup.getChildCount(); i++) {
  3.     ImageButton inoutimagebutton = (ImageButton) viewgroup
  4.       .getChildAt(i);
  5.     inoutimagebutton.setVisibility(0);
  6.     MarginLayoutParams mlp = (MarginLayoutParams) inoutimagebutton.getLayoutParams();
  7.     Animation animation = new TranslateAnimation(mlp.rightMargin-xOffset,0F,yOffset + mlp.bottomMargin, 0F);
  8. //这个地方就是相对和绝对位置的区别,其实还有4个参数没有显示出来,但是她会根据单位自动识别。原句应该是:
  9. //new TranslateAnimation(Animation.ABSOLUTE,mlp.rightMargin - xOffset, Animation.RELATIVE_TO_SELF,0F,Animation.ABSOLUTE, yOffset + mlp.bottomMargin, Animation.RELATIVE_TO_SELF,0F);
  10.     
  11.     animation.setFillAfter(true);animation.setDuration(durationMillis);
  12.     animation.setStartOffset((i * 100)
  13.       / (-1 + viewgroup.getChildCount()));
  14.     animation.setInterpolator(new OvershootInterpolator(2F));
  15.     inoutimagebutton.startAnimation(animation);
  16.    
  17.   }
  18. }
复制代码
发生移动动画出现。隐藏即为
Animation animation = new TranslateAnimation(0F,mlp.rightMargin-xOffset, 0F,yOffset + mlp.bottomMargin);

其中xOffset yOffset由布局中首尾item距离屏幕边距的距离
private static int xOffset  = 15;
private static int yOffset  = -13;
public static void initOffset(Context context){//由布局文件
  xOffset  = (int) (10.667 *context.getResources().getDisplayMetrics().density);
  yOffset  = -(int) (8.667 *context.getResources().getDisplayMetrics().density);
}
如下图
IMG_20120224_132333.jpg 
值得一提的是  interpolator的使用,PATH中使用了OvershootInterpolator以及AnticipateInterpolator。
     interpolator 被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果可以 accelerated(加速),decelerated(减速),repeated(重复),bounced(弹跳)等。
AccelerateDecelerateInterpolator 在动画开始与介绍的地方速率改变比较慢,在中间的时候加速
AccelerateInterpolator  在动画开始的地方速率改变比较慢,然后开始加速
AnticipateInterpolator 开始的时候向后然后向前甩
AnticipateOvershootInterpolator 开始的时候向后然后向前甩一定值后返回最后的值
BounceInterpolator   动画结束的时候弹起
CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线
DecelerateInterpolator 在动画开始的地方快然后慢
LinearInterpolator   以常量速率改变
OvershootInterpolator    向前甩一定值后再回到原来位置


感谢小熊屁屁不辞辛劳的努力,添加了按钮item点击放大的动画
代码  PathMenu.zip (1.3 MB, 下载次数: 367) 

另修改:添加了动画结束后将六个按钮焦点去掉的语句,防止阻挡到下面那一层的事件。


高仿小米launcher(ZAKER)跨屏拖动item 02-29最新更新 


http://www.eoeandroid.com/thread-155299-1-1.html

触发长按事件后浮动原理:
                  windowParams = new WindowManager.LayoutParams();
                windowParams.gravity = Gravity.TOP | Gravity.LEFT;
                windowParams.x = x - itemWidth / 2;
                windowParams.y = y - itemHeight / 2;
                windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
                windowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;

                ImageView iv = new ImageView(getContext());
                iv.setImageBitmap(bm);
                windowManager = (WindowManager) getContext().getSystemService(
                                Context.WINDOW_SERVICE);// "window"
                windowManager.addView(iv, windowParams);
拖动效果:
                  if (dragImageView != null) {
                        windowParams.alpha = 0.6f;
                        windowParams.x = x - itemWidth / 2;
                        windowParams.y = y - itemHeight / 2;
                        windowManager.updateViewLayout(dragImageView, windowParams);
                }
效果图:
A.png S.png d.png 
源码:  MiLaucher.zip (1.05 MB, 下载次数: 236) 
增加了滑动效果,让体验更流畅
 MiLaucher2.zip (1.06 MB, 下载次数: 132) 
长按item消失后弹出,释放动画改变
 MiLaucher3.zip (1.06 MB, 下载次数: 131) 
添加了左右滑动的支持多个gridview的功能
 MiLaucher4.zip (1.43 MB, 下载次数: 137) 
增加了跨屏拖动item替换位置的功能
源码  MiLaucher5.zip (1.09 MB, 下载次数: 252) 
替换了ZAKER界面,移动背景壁纸,3层嵌套,优化拖拽缓冲,以及滑动界面页码动画
代码包:  MiLaucher6_ZAKER.zip (1.32 MB, 下载次数: 227) 

02-06更新内容:增加了添加和删除item的事件,并修改了页码转动乱位的错误
 MiLaucher_FinalV1.zip (1.35 MB, 下载次数: 308) 

最近比较忙。没什么时间额 感谢小熊同志的意见,任何问题或改善建议请Q:451360508

02-09更新内容: 纠正了首次长按时位置错乱的问题,对删除item流程进行了改进,优化了添加item的动态添加方法,增加了感应器的使用。摇一摇可以自动排列item,清空空值项。效果APK:  MiLaucher.apk (476.09 KB, 下载次数: 74) 
代码  MiLaucher_FinalV2.zip (1.36 MB, 下载次数: 666) 

碰巧看到一个博客写launcher写得不错,原理跟这个demo挺像的。
http://blog.csdn.net/chenjie19891104/article/details/7008962

闲来无事发发更新,最近快报:
02-29:先亮截图
bg2.jpgcontent.jpg 
imgshow.jpghome.jpg 

只要学会了该上上头的小技术,再加上 原来PATH的菜单效果如此简单。布局+TranslateAnimation搞定 这个贴的PATH技术
一个小小的应用就出来咯,oh,yeah!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值