Nikita
Nikita

Reputation: 71

Animation alpha (under SurfaceView) not working

I want to make animation like fadeIn-fadeOut when user click on capture button. When I set alpha 1.0 on animatedView and android:fromAlpha="1.0", android:toAlpha="0.0" it work, but I need reverse it. Here my layout:

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

Here my animation 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>

And that's how I run it:

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

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

And nothing happens, what i'm doing wrong?

Upvotes: 0

Views: 508

Answers (1)

santosh kumar
santosh kumar

Reputation: 2962

Setting animation is not really a problem you have not arranged your layout correctly Please look at layout provided it will not be the same you want but you will be able to understand how you are going to fix it.

you are putting height ==> match_parent for every thing may be that is the reason you are not able to animate view.

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

you can use updated xml works fine here !!!

Upvotes: 0

Related Questions