【问题标题】:Android - Alter animation in resource fileAndroid - 更改资源文件中的动画
【发布时间】:2013-01-24 14:39:23
【问题描述】:

我在 overridePendingTransition 中使用了从一个活动到另一个活动的转换。不幸的是,所有 overridePendingTransition 使用的是文件的资源 id,所以我在如何编辑这个文件以使我的转换正确时遇到了麻烦。

基本上我需要做的是对 R.anim.flip_in_scale_in 进行更改,以便我可以更改从 X/到 X 的过渡值,以便根据用户的屏幕尺寸进行设置。

overridePendingTransition(R.anim.flip_in_scale_in, R.anim.stationary_item); 

如何在使用 overridePendingTransition 之前更新 R.anim.flip_in_scale_in 文件?

【问题讨论】:

    标签: android animation resources translation


    【解决方案1】:

    您无法以您想要的方式更改资源文件中的动画。

    但是,您可以创建动画以使用百分比而不是 dp 值。当动画应用于Activity 的视图时,它将完全根据视图的大小(在大多数情况下是屏幕大小)进行动画处理。

    例如:

    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate
            android:fromXDelta="100%"
            android:toXDelta="0%"
            android:duration="500"
            />
    </set>
    

    会在半秒内从视图的右侧滑到屏幕上。

    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"
            android:fromXScale="1.0"
            android:toXScale="1.4"
            android:fromYScale="1.0"
            android:toYScale="1.4"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="1000" />
    </set>
    

    这将在一秒钟内将视图增加到当前大小的 40%。无论视图大小如何,枢轴都将直接位于视图的中间。

    【讨论】:

    • 如果你没有隐式设置 xDelta 末尾带有 % 是否默认为 px?
    • 我也不知道它的默认值是什么。我假设它是dp,但假设它永远不会安全。我知道事实上这不是百分比。
    • 好的,非常感谢,准备在我拥有的不同尺寸的设备上尝试一下,看看效果如何,会告诉你的!
    • 使用百分比使其在设备间更加一致。非常感谢
    猜你喜欢
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多