【问题标题】:Animation alpha (under SurfaceView) not working动画 alpha(在 SurfaceView 下)不起作用
【发布时间】:2017-02-28 03:30:07
【问题描述】:

当用户单击捕获按钮时,我想制作像 fadeIn-fadeOut 这样的动画。 当我在 animatedView 和 android:fromAlpha="1.0", android:toAlpha="0.0" 上设置 alpha 1.0 时,它可以工作,但我需要反转它。 这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<SurfaceView
    android:id="@+id/preview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<View
    android:id="@+id/animated_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:alpha="0.0"/>

<Button
    android:id="@+id/button_capture"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true" />
</RelativeLayout>

这是我的动画 xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<alpha
    android:duration="500"
    android:fromAlpha="0.0"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:toAlpha="1.0"
    />
</set>

这就是我运行它的方式:

animClick = AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.click);

@OnClick(R.id.button_capture)
void onCaptureClick() {
    camera.takePicture(null, null, jpegCallback);
    animatedView.startAnimation(animClick);
}

什么也没发生,我做错了什么?

【问题讨论】:

    标签: android animation view surfaceview


    【解决方案1】:

    设置动画并不是你没有正确安排布局的问题 请查看布局,前提是它与您想要的不一样,但您将能够理解您将如何修复它。

    您为每件事都设置了 height ==> match_parent,这可能是您无法为视图设置动画的原因。

     <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
    
        <SurfaceView
            android:id="@+id/preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />
    
        <View
            android:id="@+id/animated_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@mipmap/ic_launcher"
            />
    
        <Button
            android:id="@+id/button_capture"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />
    </RelativeLayout>
    

    您可以在这里使用更新的 xml 工作正常!!!

    【讨论】:

    • 但我需要让 View 与 SurfaceView 完全重叠
    • 你可以使用这个 xml 文件检查更新的答案希望它有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    • 1970-01-01
    相关资源
    最近更新 更多