1

How can i decrease image size when image is falling from top to bottom?

I have developed top to bottom process through below link

Android Layout Animations from bottom to top and top to bottom on ImageView click

But i am facing one problem.How can i decrease size of image when image is falling top to bottom?

Please let me share your idea or link and code.

Please see my requirement in below image.

enter image description here

Adam
  • 444
  • 5
  • 18

2 Answers2

2

you can apply scale transformation to that view.

Matrix matrix = new Matrix();
matrix.setScale(valueX, valueY);
view.setTransform(matrix); 

For imageView

imageView.setImageMatrix(matrix);
minhazur
  • 4,928
  • 3
  • 25
  • 27
1

I solved my question.I hope everyone will like it.

1.Create anim/zoom_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fillAfter="true">
<scale
    android:duration="5000"
    android:fromXScale="100%"
    android:fromYScale="100%"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="50%"
    android:toYScale="50%" />

<translate
    android:duration="5000"
    android:fromYDelta="10%"
    android:toYDelta="50%" />

2.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView android:id="@+id/imgvw"
    android:layout_width="wrap_content"
    android:layout_height="250dp"
    android:src="@mipmap/ic_launcher"/>
<Button
    android:id="@+id/btnZoomIn"
    android:layout_below="@+id/imgvw"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Zoom In" android:layout_marginLeft="100dp" />
<Button
    android:id="@+id/btnZoomOut"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/btnZoomIn"
    android:layout_toRightOf="@+id/btnZoomIn"
    android:text="Zoom Out" />
</RelativeLayout>

3.MainActivity.java file

public class MainActivity extends AppCompatActivity {
private Button btnzIn;
private Button btnzOut;
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btnzIn = (Button)findViewById(R.id.btnZoomIn);
    btnzOut = (Button)findViewById(R.id.btnZoomOut);
    img = (ImageView)findViewById(R.id.imgvw);
  /*  btnzIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

          //  img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_in));
            img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down));
           // img.clearAnimation();
        }
    });*/
    btnzOut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        //    img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up));
            img.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out));

        }
    });
}
Adam
  • 444
  • 5
  • 18