在Android中动画后更改实际位置
我正在我的应用程序中使用动画。有一个图像是我实现动画的地方。在Android中动画后更改实际位置,android,android-animation,Android,Android Animation,我正在我的应用程序中使用动画。有一个图像是我实现动画的地方。 但在动画之后,我无法点击图像。我搜索并阅读了stackoverflow的答案,最后发现动画只对原始像素进行dram。所以,我需要移动实际位置的视图。我发现通过在动画之后设置布局参数,这是可能的。但我不知道我怎么能做到。这是我用来制作动画的代码 anim.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.and
但在动画之后,我无法点击图像。我搜索并阅读了stackoverflow的答案,最后发现动画只对原始像素进行dram。所以,我需要移动实际位置的视图。我发现通过在动画之后设置布局参数,这是可能的。但我不知道我怎么能做到。这是我用来制作动画的代码 anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="-50%p"
android:duration="500" />
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.45"
android:toYScale="0.45" >
</scale>
</set>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/btnCapturePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="17dp"
app:srcCompat="@drawable/capture_picture" />
</RelativeLayout>
由于我不知道什么是新参数,我如何在动画之后设置新布局参数新参数有没有办法从animation.xml文件中获取这些新参数,并将其设置为btnCameraPicinsideAnimationListener
我读了很多关于stackoverflow的问题,但大多数都是在java类上使用动画,而不是从xml文件中使用动画。有人能告诉我动画后的新参数是什么吗?尝试在anim.xml文件中添加以下行
android:fillAfter = "true"
简短回答: 您应该使用属性动画 原因: 属性动画与视图动画的区别 视图动画系统提供仅为视图对象设置动画的功能,因此如果要为非视图对象设置动画,则必须实现自己的代码。视图动画系统也受到限制,因为它只显示视图对象的几个方面来进行动画,例如视图的缩放和旋转,但不显示背景色 视图动画系统的另一个缺点是,它仅修改绘制视图的位置,而不是实际视图本身。例如,如果设置按钮在屏幕上移动的动画,则按钮绘制正确,但可以单击按钮的实际位置不会更改,因此您必须实现自己的逻辑来处理此问题 使用属性动画系统,这些约束将被完全删除,您可以为任何对象(视图和非视图)的任何属性设置动画,并且对象本身将被实际修改。属性动画系统在执行动画的方式上也更加健壮。在较高级别上,可以将动画角色指定给要设置动画的属性,例如颜色、位置或大小,并可以定义动画的各个方面,例如多个动画角色的插值和同步 以下是链接:
android:fillAfter = "true"