7.ImageView in Android
7.ImageView in Android
java
ImageView imageView = findViewById(R.id.myImageView);
imageView.animate().alpha(0.5f).setDuration(500).start();
This will fade the ImageView to 50% opacity over a duration of 500
milliseconds.
2. Scaling Animation:
• Use the scaleX() and scaleY() methods to scale the ImageView in the X and
Y dimensions, respectively.
• Example:
java
ImageView imageView = findViewById(R.id.myImageView);
imageView.animate().scaleX(1.2f).scaleY(1.2f).setDuration(1000).start();
This will scale the ImageView to 120% of its original size over a duration of
1 second.
3. Translation Animation:
• Use the translationX() and translationY() methods to move
the ImageView horizontally and vertically, respectively.
• Example:
java
ImageView imageView = findViewById(R.id.myImageView);
imageView.animate().translationX(100f).translationY(50f).setDuration(750
).start();
This will move the ImageView 100 pixels to the right and 50 pixels down
over a duration of 750 milliseconds.
4. Rotation Animation:
• Use the rotation(), rotationX(), and rotationY() methods to rotate
the ImageView.
• Example: