【问题标题】:Difficulties fading out and hiding Relative Layout淡出和隐藏相对布局的困难
【发布时间】:2013-07-02 14:43:15
【问题描述】:

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

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

这是我的功能:

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>

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

我希望有更多经验的人会花时间告诉我我做错了什么。

【问题讨论】:

    标签: java android animation fade alpha


    【解决方案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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      相关资源
      最近更新 更多