Foa*_*Guy 7 animation android relativelayout
我有一个活动,其布局只包含一个VideoView.这是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>
Run Code Online (Sandbox Code Playgroud)
我试图在停止播放后将此动画应用于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>
Run Code Online (Sandbox Code Playgroud)
这显示出完美的效果.但是如果我在布局中从LinearLayout切换到RelativeLayout,则动画不再有效,视频会在停止之前显示的最后一帧上冻结.
为什么我的活动中的根布局类型会导致动画无法正常运行?
编辑:如果我添加此TextView,添加到怪异
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ">
</TextView>
Run Code Online (Sandbox Code Playgroud)
对于VideoView下面的RelativeLayout,动画将起作用.但是,如果我从这个android:text元素中取出空间,那么它又回来了.OO
编辑:我已经将Beowulf Bjornson的赏金授予使用新动画框架的好处.
但是我仍然非常感兴趣,如果有人在这种情况下弄清楚旧式动画的情况,我会非常乐意为此提出更多的观点.
我不确定使用第三方库是否适合您,但我强烈推荐NineOldAndroids,因此您可以在早期版本的Android中使用3.0+的动画功能.他们使这项工作变得更容易.
这是链接:http://nineoldandroids.com/
然后,在您的活动上,您可以做一些简单的事情:
VideoView view = (VideoView) findViewById(R.id.videoplayer);
animate(view).scaleX(0).scaleY(0).setDuration(500L);
Run Code Online (Sandbox Code Playgroud)
我已经使用RelativeLayout测试了它,它按预期工作.
编辑:如果你想使用本机蜂窝实现,这个特定的API是3.1+,它应该像本机一样使用如下:
view.animate().scaleX(0).scaleY(0).setDuration(500L);
Run Code Online (Sandbox Code Playgroud)
如果你希望本机支持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();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2810 次 |
最近记录: |