【问题标题】:Slide from left View animation从左侧滑动查看动画
【发布时间】:2018-03-19 22:21:59
【问题描述】:

鉴于:

ImageView 及其 DrawableBitmap

任务:

需要为ImageView 制作从左侧滑动扩展效果,不超过ImageView 的界限。

我尝试使用翻译动画:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
    <translate android:fromXDelta="-100%" android:toXDelta="0%"
               android:fromYDelta="0%" android:toYDelta="0%"
               android:duration="3000"/>
</set>

但是当Bitmap 最初从 ImageView 的左侧绘制(动画大约完成了 80%)时,会得到如下图所示的不必要的效果:

那么,当ImageView 内容被拉出边界时,是否可以隐藏它?或者也许还有其他更优雅的解决方案?

提前谢谢你。

【问题讨论】:

    标签: android animation imageview slide expand


    【解决方案1】:

    我能理解的是你有那个盒子,你希望加载视图从左到右展开。如果是这种情况,那么请考虑使用缩放动画而不是平移动画。

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale
            android:duration="3000"
            android:fromXScale="0.0"
            android:fromYScale="1.0"
            android:pivotX="0%"
            android:pivotY="0%"
            android:toXScale="1.0"
            android:toYScale="1.0" />
    </set>
    

    【讨论】:

    • 谢谢,但这不是我需要的。 ImageView 内容不能有任何收缩或拉伸。它必须像“从隧道中驶出的火车”
    • 你可以玩Z轴。保留需要在 imageView 内容上方可见的内容。就像我从上面的图片中可以理解的那样,除了那个背景之外,其他所有东西都可以在 imageView 之上。这样 ImageView 将在视图的其余部分下方滑动。这是你想要的吗?
    • 是的。这可能是一个可能的答案,但它可能看起来像“便宜的解决方法”。谢谢你的答案。如果没有其他方法,我将应用此解决方案。
    【解决方案2】:

    使用 imageView.animate().alpha(1).translationX(imageView.getHeight).setDuration(500);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2011-07-06
      相关资源
      最近更新 更多