1

I'm developing an m3u livestreaming app, and I want to show all of the channels in a listview. Now I don't know how to make a listview appear from the right as shown in the picture with a slide animation when a button is clicked and make it disappear (slide out animation) when I click the button again.

Can somebody help me out ?picture of what I want to achieve

Edit: I tried this, but it didn't work unfortunately.

//slide in imgbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imgbuttonisclicked = true;
                ValueAnimator widthAnimator = ValueAnimator.ofInt(0, 255);
                widthAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int animatedValue = (int) animation.getAnimatedValue();
                        list.getLayoutParams().width = animatedValue;
                        list.requestLayout();
                    }
                });

   //slide out      if (imgbuttonisclicked){
                    widthAnimator = ValueAnimator.ofInt(255, 0);
                    widthAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            int animatedValue = (int) animation.getAnimatedValue();
                            list.getLayoutParams().width = animatedValue;
                            list.requestLayout();
                        }
                    });
                }
            }
        });

1 Answers1

0

You could perhaps play on the width property of the list. Set it to 0 at first then on the button click event animate it to a bigger width. You can learn more about property animation in this article.

Edit: This answer provides a better solution.

Elyes Mansour
  • 126
  • 1
  • 6
  • Thank you. I experimented with the code in the article and tried this (see my edit code), but it didn't work :( – Creesch 2.0 Jun 23 '19 at 12:12
  • Your code is missing a call to widthAnimator.start(). You could also add duration with setDuration(). I've added a link in my post to another stackoverflow topic that could provide a better solution. – Elyes Mansour Jun 23 '19 at 23:04