【问题标题】:Centering a circular reveal animation使圆形显示动画居中
【发布时间】:2015-07-07 22:13:05
【问题描述】:

我正在尝试创建一个从 View (API 21+) 的中心开始的圆形显示动画。我尝试将View.getLeft()View.getRight() 的平均值用于x 和View.getTop()View.getBottom() 用于y(这是sample 所做的,但如果我的视图被CoordinatorLayout 偏移,则值是错误的. 我正在获取OnPreDrawListener 中的值,因此已经测量了视图。

【问题讨论】:

    标签: android animation


    【解决方案1】:

    我发现使用 View.getDrawingRect() 可以解决问题。

    private Animator createCenteredReveal(View view) {
      // Could optimize by reusing a temporary Rect instead of allocating a new one
      Rect bounds = new Rect();
      view.getDrawingRect(bounds);
      int centerX = bounds.centerX();
      int centerY = bounds.centerY();
      int finalRadius = Math.max(bounds.width(), bounds.height());
      return ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0f, finalRadius);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      • 2018-10-18
      相关资源
      最近更新 更多