Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中完美添加向下滑动和反弹动画?_Android_Xml_Animation - Fatal编程技术网

如何在android中完美添加向下滑动和反弹动画?

如何在android中完美添加向下滑动和反弹动画?,android,xml,animation,Android,Xml,Animation,我试图制作一个文本视图的动画,它从顶部滑到中心,然后反弹并保持静止。我放了一个代码,它可以完美地反弹,但我遇到的问题是它没有显示向下滑动的效果。文本仅在动画持续时间结束后显示,然后反弹。xml中的代码如下所示: <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" android:fillAfter="false"> <translat

我试图制作一个文本视图的动画,它从顶部滑到中心,然后反弹并保持静止。我放了一个代码,它可以完美地反弹,但我遇到的问题是它没有显示向下滑动的效果。文本仅在动画持续时间结束后显示,然后反弹。xml中的代码如下所示:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:fillAfter="false">

<translate
    android:duration="1000"
    android:fillAfter="true"
    android:fromYDelta="-100%p"
    android:toYDelta="0%p"/>

<scale
    android:interpolator="@android:anim/bounce_interpolator"
    android:duration="500"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="0.0"
    android:startOffset="1000"
    android:toXScale="1.0"
    android:toYScale="1.0"/>

如果有人能帮我解决这个问题,那就太好了。

我想你正在使用

android:toYDelta="0%p"
这就是造成问题的原因。您之所以使用此选项,可能是因为您在屏幕中居中显示了文本视图。因此,在我看来,您不应该在布局中居中显示TextView,而应该在xml中执行类似的操作

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
   <TextView 
   android:id="@+id/tv_text"
   android:layout_centerHorizontal="true"
   android:text="23"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   />

然后将设置的动画更改为

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:shareInterpolator="false" >

<translate
    android:duration="1000"
    android:fromYDelta="-100%p"
    android:toYDelta="50%p" 
    />

<scale
    android:duration="500"
    android:fromXScale="1.0"
    android:fromYScale="0.0"
    android:interpolator="@android:anim/bounce_interpolator"
    android:startOffset="1000"
    android:toXScale="1.0"
    android:toYScale="1.0" />

</set>