Skip to content
Advertisement

Android Java Play gifs only once time

I want geese when a user double-clicks on a post a gif is played. For this I used pl.droidsonroids.gif.GifImageView like so:

<pl.droidsonroids.gif.GifImageView
            android:layout_width="match_parent"
            android:layout_height="303dp"

            android:src="@drawable/likepopgif"
            android:visibility="invisible"
            />

and to get it started I just used visible and invisible when needed:

 holder.imgPost.setOnTouchListener(new View.OnTouchListener() {
                    @SuppressLint("ClickableViewAccessibility")
                    GestureDetector gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener(){

                        @SuppressLint("ClickableViewAccessibility")
                        @Override
                        public boolean onDoubleTap(MotionEvent e) {
                            Toast.makeText(visualizzaPost.this, "Liked post", Toast.LENGTH_SHORT).show();
                            holder.gifLike.setVisibility(View.VISIBLE);
                            holder.gifLike.setVisibility(View.INVISIBLE);
                            return super.onDoubleTap(e);
                        }
                    });
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        gestureDetector.onTouchEvent(event);
                        return false;
                    }
                });

obviously, however, the invisible is asynchronous with the seconds of the animation length. I’m looking for an event / property or anything else that tells the app when the animation has played and then I can make it invisible.

if i use app:loopCount="1" remains immoral when the loop ends in this way:

enter image description here

Advertisement

Answer

If you want a gif to play once you can do something like this:

<pl.droidsonroids.gif.GifImageView
            android:layout_width="match_parent"
            android:layout_height="303dp"

            android:src="@drawable/likepopgif"
            android:visibility="invisible"
            app:loopCount="1"
            />

And if you want to know when the gif ends you can use getDuration() and check if it is the same as getCurrentPosition()

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement