1
votes

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

1 Answers

0
votes

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.