Question

I am trying to Hide/Show a TableLayout on button click but the animation listener is not working here is the code i am trying

Slide_down = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
Slide_up = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_up);

searchArea = (TableLayout) findViewById(R.id.TableLayout1);
        SearchButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (check_tableView == 0) {

                    Slide_up.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            searchArea.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            searchArea.setVisibility(View.GONE);
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });


                    check_tableView = 1;
                } else {

                    Slide_down.setAnimationListener(new Animation.AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {

                            searchArea.setVisibility(View.GONE);
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            searchArea.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                    check_tableView = 0;
                }
            }

        });
Was it helpful?

Solution

//just start animation

searchArea = (TableLayout) findViewById(R.id.TableLayout1);
        SearchButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (check_tableView == 0) {


searchArea.startAnimation(Slide_up);
}
});

OTHER TIPS

You just set animation listener outside of onClickListener. No need of setting each time View is clicked. Also make sure that you are calling searchArea.startAnimation(Slide_up) and searchArea.startAnimation(Slide_down) method. Call start animation method inside onClickListener.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top