【问题标题】:Slide up Animation using ObjectAnimator使用 ObjectAnimator 向上滑动动画
【发布时间】:2016-10-21 17:12:38
【问题描述】:

我正在尝试将 ObjectAnimator 用于上滑翻译动画,因为我们知道,如果我们使用这样的普通翻译动画,onclicklistener 将不起作用,

<translate
    android:duration="1000"
    android:fromYDelta="100%"
    android:toYDelta="10%" />

上面的 xml 代码可以正常工作,但正如我之前所说,onclicklistener 在动画后不起作用。 我尝试了像下面这样的 ObjectAnimator

ObjectAnimator mover = ObjectAnimator.ofFloat(filterLayout, "translationY", 1.0f, 0.1f);
mover.start();

但它给出的结果与 translate xml 不同。

任何帮助将不胜感激。

【问题讨论】:

    标签: android android-animation android-xml


    【解决方案1】:

    您的问题是您传递给 ObjectAnimator 的值不是百分比,而是绝对值。

    所以你必须计算视图的高度,然后将它传递给 ObjectAnimator,即。

    ObjectAnimator.ofFloat(filterLayout,"translationY",calcHeight,calcHeight * 0.1f);
    

    【讨论】:

      【解决方案2】:

      我知道已经晚了,但请检查以下代码,看看是否适用于您的情况。我将您共享的 XML 代码作为对此的参考。

      ObjectAnimator.ofPropertyValuesHolder(
              view,
              PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 100.0f, 10.0f));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-20
        相关资源
        最近更新 更多