2

I'm trying to do a simple fade-out animation for my "custom" media controller.

The problem I'm having is that the layout does not fade-out, it just disappears after a second (as if I would set the Visibility to GONE with a 1 second delay).

This is my function:

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

And the layout that I'm trying to hide:

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

It's worth mentioning that all this is being used inside a fragment.

I'm hoping that someone with a bit more experience will take the time and let me know what I'm doing wrong.

4

1 回答 1

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());
于 2013-07-02T14:51:43.107 回答