RelativeLayout的导致动画不工作? [英] RelativeLayout causes animation not to work?

查看:422
本文介绍了RelativeLayout的导致动画不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局中只包含一个VideoView活动。下面是XML:

I have an activity whose layout only contains a VideoView. Here is the 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>

我想这个动画应用到VideoView停止播放后:

I am trying to apply this animation to the VideoView after it stops playing:

<?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的话动画不再可行,视频只是冻结所显示停止前的最后一帧上。

This works perfectly as it is shown. But if I switch from LinearLayout to RelativeLayout in the layout then the animation no longer works and the video just freezes on the last frame that is shown before it stops.

为什么根布局在我的活动类型引起的动画不能正常工作?

Why would the type of root layout in my activity cause an animation not to function properly?

编辑:为了增加古怪,如果我加入这个TextView的

To add to the weirdness if I add this TextView

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

要低于VideoView的RelativeLayout的那么动画会工作。但是如果我乘坐空间了Android系统:这个文本元素,则其回不工作。 o.O

To the RelativeLayout below the VideoView then the animation will work. However if I take the space out of the android:text element of this then it is back to not working. o.O

编辑:我已经获得了赏金贝奥武夫比昂松使用较新的动画框架的很好的提示。

I've awarded the bounty to Beowulf Bjornson for the nice tip of using the newer animation framework.

不过,我还是很感兴趣,如果有人曾经计算出什么,在这种情况下,老式的动画怎么回事,我会更乐意抛出一些更多的点了吧。

But I am still very interested if anyone ever figures out what is going on with the old style animations in this situation I'd be more than happy to throw some more points up for it.

推荐答案

我不知道,如果使用的是第三方库,对你是一个可行的解决方案,但我强烈建议NineOldAndroids,所以你可以使用的动画功能3.0+在早期版本的Andr​​oid系统。他们做这个工作比较容易的方式。

I'm not sure if using a third-party library is a viable solution for you, but I strongly recommend NineOldAndroids, so you can use the Animation capabilities of 3.0+ in earlier versions of Android. They make this job WAY easier.

这里的链接: http://nineoldandroids.com/

然后,在你的活动,你可以做一些简单的:

Then, on you activity you can do something as easy as:

VideoView view = (VideoView) findViewById(R.id.videoplayer);
animate(view).scaleX(0).scaleY(0).setDuration(500L);

我就用RelativeLayout的和它的作品如预期测试。

I've tested it using RelativeLayout and it works as expected.

编辑:如果您希望使用本地蜂窝实现,这个特定的API是3.1+,它应该nativelly使用这样的:

If you wish to use the native honeycomb implementation, this specific API is 3.1+ and it should be used nativelly like the following:

view.animate().scaleX(0).scaleY(0).setDuration(500L);

如果你想nativelly支持3.0,你将不得不使用这样的:

And if you wish to nativelly support 3.0, you'll have to use it like this:

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();

这篇关于RelativeLayout的导致动画不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆