使用XML实现从右上角到左下角的Android动画

3

我想从右侧的操作栏打开一个对话框。 我希望动画从右上角到左下角加载。 这是我的代码,但它从左上角到右下角加载。 我已经尝试过调整但没有成功。 谢谢任何帮助。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale android:fromYScale="0" android:toYScale="1.0"
        android:fromXScale="0" android:toXScale="1.0" 
        android:duration="500"/>
</set>
2个回答

7

很抱歉晚了几个月才加入,但最好的方法和推荐的方法是:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:interpolator="@android:anim/decelerate_interpolator">
     <scale
            android:fromYScale="0"
            android:toYScale="1.0"
            android:startOffset="0"
            android:duration="1200"
            android:fromXScale="0"
            android:toXScale="1.0"
            android:fillAfter="true"
            android:pivotX="100%" />
</set>

正确的方法是使用动画起始点的枢轴点来完成。

1

这个 对你会很有帮助。

我尝试了类似这样的东西。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:interpolator="@android:anim/decelerate_interpolator">
    <scale
            android:fromYScale="0"
            android:toYScale="1.0"
            android:startOffset="0"
            android:duration="1200"
            android:fromXScale="0"
            android:toXScale="1.0"
            android:fillAfter="true" />
    <translate android:fromXDelta="100%" android:fromYDelta="-100%"
               android:duration="700" />
</set>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接