困难淡出并隐藏相对布局

时间:2013-07-02 14:43:16

标签: java android animation fade alpha

我正在尝试为我的“自定义”媒体控制器做一个简单的淡出动画。

我遇到的问题是布局不会淡出,它会在一秒后消失(好像我会将亮度设置为GONE,延迟时间为1秒)。

这是我的功能:

private void fadeOut(final View view) {
        final AlphaAnimation fadeOutAnimation = new AlphaAnimation(1.0F,  0.0F);
        fadeOutAnimation.setDuration(1000);
        fadeOutAnimation.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                view.setVisibility(View.GONE);
            }
        });
        view.startAnimation(fadeOutAnimation);
    }

我试图隐藏的布局:

<RelativeLayout
            android:id="@+id/videoControllerContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="0dp"
            android:alpha="50"
            android:background="@color/DarkGrey" >

            <ImageButton
                android:id="@+id/playVideoButton"
                android:layout_width="wrap_content"
                android:layout_height="50dip"
                android:layout_alignParentLeft="true"
                android:background="@null"
                android:contentDescription="@string/playButton"
                android:scaleType="fitCenter"
                android:src="@drawable/play" />

            <ImageButton
                android:id="@+id/fullScreenVideoButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:background="@null"
                android:contentDescription="@string/fullscreen"
                android:src="@drawable/fullscreen" />
        </RelativeLayout>

值得一提的是,所有这些都在片段中使用。

我希望有经验的人会花时间让我知道我做错了什么。

1 个答案:

答案 0 :(得分:1)

我认为你应该在anim xml文件中有这个,你需要这个:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
       android:interpolator="@android:anim/accelerate_interpolator"
       android:duration="1000"/>
</set>

我认为你的问题是内插器没有定义。因此,请尝试在代码中添加此行等效项:

android:interpolator="@android:anim/accelerate_interpolator"

希望有所帮助

编辑:做了一点研究,看起来你想说

fadeOutAnimation.setInterpolator(new AccelerateInterpolator());