0

I am working on android application in which on button click i am giving width and height to my linear layout to make it full screen and by clicking again i am giving its width and height to 1dp. I just need to animate this thing like when i press the button it will slowly animate to full screen and on again pressing of button it will slowly animate to 1dp width and height. I have used translate for this thing but it didn't work in this scenario.

btnResize.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            if(resize==true){
                                otherLayout.setLayoutParams(new LayoutParams(1, 1));
                                resize=false;
                            }else{
                                resize=true;
                                int height = LayoutParams.WRAP_CONTENT;
                                int width = LayoutParams.MATCH_PARENT;

//                              ImageView imageView = (ImageView)findViewById(R.id.imageView);
//
//                              Animation animZoomin = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_in);
//
//                              imageView.startAnimation(animZoomin);
                                otherLayout.setLayoutParams(new LayoutParams(width, height));
                            }


                        }
                    });
android_explorer
  • 345
  • 1
  • 3
  • 10

1 Answers1

1

You can use scale animation:

  • Start by calculating your screen size: Get screen dimensions in pixels

  • Next get the current view width and height.

  • Calculate the ratio between the 2 to get the scale factor (hint: screenH / viewH)

  • Next use view.animate().scaleX(xRatio).scaleY(yRatio) to start the animation

You may need to translate the view too if it is not centered in the screen

Other option is to use this method: Expand/collapse animation

Community
  • 1
  • 1
Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82