zoukankan      html  css  js  c++  java
  • Path布局+TranslateAnimation

    提取了下PATH的菜单的那种动画效果。先看贴图,呵呵

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

    public static void startAnimationsIn(ViewGroup viewgroup,int durationMillis) {
     
      for (int i = 0; i < viewgroup.getChildCount(); i++) {
        ImageButton inoutimagebutton = (ImageButton) viewgroup.getChildAt(i);
        inoutimagebutton.setVisibility(0);
     
        MarginLayoutParams mlp = (MarginLayoutParams) inoutimagebutton.getLayoutParams();
        Animation animation = new TranslateAnimation(mlp.rightMargin-xOffset,0F,yOffset + mlp.bottomMargin, 0F);
     
    //这个地方就是相对和绝对位置的区别,其实还有4个参数没有显示出来,但是她会根据单位自动识别。原句应该是: 
    //new TranslateAnimation(Animation.ABSOLUTE,mlp.rightMargin - xOffset, Animation.RELATIVE_TO_SELF,0F,Animation.ABSOLUTE, yOffset + mlp.bottomMargin, Animation.RELATIVE_TO_SELF,0F);
     
        
        animation.setFillAfter(true);animation.setDuration(durationMillis);
        animation.setStartOffset((i * 100)
           / (-1 + viewgroup.getChildCount()));
         animation.setInterpolator(new OvershootInterpolator(2F));
         inoutimagebutton.startAnimation(animation);
       } 
    }
     

    发生移动动画出现。隐藏即为:

    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);
     }

    值得一提的是 interpolator的使用,PATH中使用了OvershootInterpolator以及AnticipateInterpolator。
    interpolator 被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果可以 accelerated(加速),decelerated(减速),repeated(重复),bounced(弹跳)等。
    AccelerateDecelerateInterpolator 在动画开始与介绍的地方速率改变比较慢,在中间的时候加速
    AccelerateInterpolator  在动画开始的地方速率改变比较慢,然后开始加速
    AnticipateInterpolator 开始的时候向后然后向前甩
    AnticipateOvershootInterpolator 开始的时候向后然后向前甩一定值后返回最后的值
    BounceInterpolator   动画结束的时候弹起
    CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线
    DecelerateInterpolator 在动画开始的地方快然后慢
    LinearInterpolator   以常量速率改变
    OvershootInterpolator    向前甩一定值后再回到原来位置


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

  • 相关阅读:
    Kubernetes 系列(八):搭建EFK日志收集系统
    Kubernetes 系列(七):持久化存储StorageClass
    Kubernetes 系列(六):持久化存储 PV与PVC
    .Net Core自动化部署系列(三):使用GitLab CI/CD 自动部署Api到Docker
    Ocelot自定义管道中间件
    生产环境项目问题记录系列(二):Docker打包镜像Nuget包因权限问题还原失败
    .Net Core 商城微服务项目系列(十四):分布式部署携程Apollo构建配置中心
    IT人该如何未雨绸缪,不断提升自己的竞争力?同时尽量避免风险?
    Session跟Cookie简单的理解
    软件测试中高级面试提问
  • 原文地址:https://www.cnblogs.com/vus520/p/2561974.html
Copyright © 2011-2022 走看看