Android RelativeLayout导致动画无法工作?

Android RelativeLayout导致动画无法工作?,android,animation,android-relativelayout,Android,Animation,Android Relativelayout,我有一个活动,其布局仅包含一个视频视图。以下是xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <VideoView and

我有一个活动,其布局仅包含一个视频视图。以下是xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">


  <VideoView
android:id="@+id/videoplayer"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
>
</VideoView>

我尝试在视频视图停止播放后将此动画应用于视频视图:

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

</set>

如图所示,这一点非常有效。但是,如果我在布局中从LinearLayout切换到RelativeLayout,则动画将不再工作,视频将在停止前显示的最后一帧冻结

为什么“我的活动”中的根布局类型会导致动画无法正常运行

编辑:如果我添加此文本视图,则会增加怪诞感

<TextView
android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" ">
</TextView> 

到VideoView下面的RelativeLayout,则动画将工作。然而,如果我把这个android:text元素中的空格去掉,那么它就不会工作了。o、 o

编辑:贝奥武夫·比约森(Beowulf Bjornson)因使用新的动画框架而获得赏金


但我仍然非常感兴趣,如果有人能弄清楚在这种情况下老式动画到底发生了什么,我会非常乐意为它多加一些分数。

我不确定,但在我的应用程序中,我有RelativeLayout和Animaion,而且视频工作正常

如果VideoView是布局的唯一视图,则将相对的yout height和Width设置为fill_parent,也设置为VideoView,然后重试


希望它能起作用。如果没有,请告诉我。

我不确定使用第三方库对您来说是否是一个可行的解决方案,但我强烈推荐NineodelDroids,这样您就可以在早期版本的Android中使用3.0+的动画功能。他们使这项工作更容易

以下是链接:

然后,在您的活动中,您可以做一些简单的事情:

VideoView view = (VideoView) findViewById(R.id.videoplayer);
animate(view).scaleX(0).scaleY(0).setDuration(500L);
我已经使用RelativeLayout对其进行了测试,结果与预期相符

编辑:如果您希望使用本机蜂窝状实现,此特定API为3.1+,本机使用时应如下所示:

view.animate().scaleX(0).scaleY(0).setDuration(500L);
如果您希望在本机上支持3.0,您必须这样使用它:

AnimatorSet set = new AnimatorSet();
set.playTogether(
    ObjectAnimator.ofFloat(view, "scaleX", 1.0f, 0.0f),
    ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 0.0f),
);
set.setDuration(500).start();

如何在Java代码中调用动画?请把它放在这里。也许我能理解为什么它会冻结。这是一个整洁的图书馆,我肯定计划去看看它。但是我已经在为蜂巢公司构建项目,所以我应该已经可以访问新的动画API了。我将在周一进行测试,看看使用那个新的API是否能解决我的问题。当然。我添加了一些本地示例,以防对您有所帮助:)