Does RelativeLayout make animation not work?

I have an activity that only has a VideoView in the layout. 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> 

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

 <?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> 

This works great as shown. But if I switch from LinearLayout to RelativeLayout in the layout, the animation will no longer work, and the video just freezes in the last frame that appears before it stops.

Why does the type of root layout in my activity make the animation work incorrectly?

EDIT: add to weirdness if I add this TextView

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

In the RelativeLayout below the VideoView, the animation will work. However, if I select a space from android: a text element, then it does not work again. oo

EDIT: I awarded Bounty Beowulf Bjornson for good advice on using the new animation environment.

But Iā€™m still very interested if someone ever finds out what happens with the old-style animation in this situation, I would be more than happy to give a few more points for this.

+7
source share
2 answers

I'm not sure if using a third-party library is a viable solution for you, but I highly recommend NineOldAndroids, so you can use the features of Animation 3.0+ in earlier versions of Android. They facilitate this work.

Here's the link: http://nineoldandroids.com/

Then you can do something as simple as:

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

I tested it using RelativeLayout and it works as expected.

EDIT:. If you want to use the embedded cellular implementation, this particular API is 3.1+ and should be used as shown below:

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

And if you want nativelly to support 3.0, you will have to use it as follows:

 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(); 
+9
source

I'm not sure, but in my application I have RelativeLayout and Animaion, and also the video works fine.

If VideoView is just a layout view, then set heightLayout height and Width as fill_parent, as well as for VideoView, and then try.

Hope this works. If not, let me know.

+1
source

All Articles