This can be done using ValueAnimator .
The presence of this layout as activity content:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"> <View android:id="@+id/view" android:layout_width="170dp" android:layout_height="170dp" android:background="#3143ff"/> </FrameLayout>
And in onCreate() action:
final View view = findViewById(R.id.view); final View contentView = findViewById(R.id.content_frame); contentView.setOnClickListener(v -> { final int screenWidth = contentView.getWidth(); final int screenHeight = contentView.getHeight(); ValueAnimator widthAnimator = ValueAnimator.ofInt(view.getWidth(), screenWidth); ValueAnimator heightAnimator = ValueAnimator.ofInt(view.getHeight(), screenHeight); widthAnimator.setDuration(1500); heightAnimator.setDuration(1500); widthAnimator.addUpdateListener(animation -> { view.getLayoutParams().width = (int) animation.getAnimatedValue(); view.requestLayout(); }); heightAnimator.addUpdateListener(animation -> { view.getLayoutParams().height = (int) animation.getAnimatedValue(); view.requestLayout(); }); widthAnimator.start(); heightAnimator.start(); });
final View view = findViewById(R.id.view); final View contentView = findViewById(R.id.content_frame); contentView.setOnClickListener(v -> { final int screenWidth = contentView.getWidth(); final int screenHeight = contentView.getHeight(); ValueAnimator widthAnimator = ValueAnimator.ofInt(view.getWidth(), screenWidth); ValueAnimator heightAnimator = ValueAnimator.ofInt(view.getHeight(), screenHeight); widthAnimator.setDuration(1500); heightAnimator.setDuration(1500); widthAnimator.addUpdateListener(animation -> { view.getLayoutParams().width = (int) animation.getAnimatedValue(); view.requestLayout(); }); heightAnimator.addUpdateListener(animation -> { view.getLayoutParams().height = (int) animation.getAnimatedValue(); view.requestLayout(); }); widthAnimator.start(); heightAnimator.start(); });
This will be the result:

Referral API
We ourselves have implemented this animation. But why don't we let the system take care of creating all these animators?
There Transitions API , which will take on a heavy lift. All we need to do is ask the framework to detect layout changes, create appropriate animators, and run animations.
So, all of the above code can be changed to the following, which will lead to an exact exit:
contentView.setOnClickListener(v -> { final int screenWidth = contentView.getWidth(); final int screenHeight = contentView.getHeight();
contentView.setOnClickListener(v -> { final int screenWidth = contentView.getWidth(); final int screenHeight = contentView.getHeight();
source share