0% found this document useful (0 votes)
23 views3 pages

Activity - Main - XML Fade - Anim - XML

The document contains XML code for animations and Java code to apply different animations to an image view when buttons are clicked. The XML defines fade, zoom, rotate, and slide animations. The Java code gets animation resources and starts the corresponding animation on the image view when each button is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Activity - Main - XML Fade - Anim - XML

The document contains XML code for animations and Java code to apply different animations to an image view when buttons are clicked. The XML defines fade, zoom, rotate, and slide animations. The Java code gets animation resources and starts the corresponding animation on the image view when each button is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Activity_main.xml Fade_anim.

xml
<RelativeLayout xmlns:android="http://schemas. <?xml version="1.0" encoding="utf-8"?>
android.com/apk/res/android" <alpha
xmlns:tools="http://schemas. xmlns:android="http://schemas.android.com/apk/res/androi
android.com/tools" d"
android:layout_width="match_parent" android:duration="1000"
android:layout_height="match_parent" android:fromAlpha="0.0"
tools:context=".MainActivity"> android:toAlpha="1.0" />
<ImageView
android:id="@+id/imageView" Slide_anim.xml
android:layout_width="200dp" <?xml version="1.0" encoding="utf-8"?>
android:layout_height="200dp" <translate
xmlns:android="http://schemas.android.com/apk/res/androi
android:src="@drawable/ic_launcher_backgroun d"
d" android:duration="1000"
android:layout_centerHorizontal="true" android:fromXDelta="-100%"
android:layout_marginTop="50dp"/> android:toXDelta="0%"
<Button android:fromYDelta="0%"
android:id="@+id/buttonFade" android:toYDelta="0%" />
android:layout_width="wrap_content"
android:layout_height="wrap_content" Zoom_anim.xml
android:text="Fade" <?xml version="1.0" encoding="utf-8"?>
android:layout_below="@id/imageView" <scale
android:layout_alignParentStart="true" xmlns:android="http://schemas.android.com/apk/res/androi
android:layout_margin="16dp"/> d"
<Button android:duration="1000"
android:id="@+id/buttonZoom" android:fromXScale="0.0"
android:layout_width="wrap_content" android:fromYScale="0.0"
android:layout_height="wrap_content" android:pivotX="50%"
android:text="Zoom" android:pivotY="50%"
android:layout_below="@id/imageView" android:toXScale="1.0"
android:layout_alignParentEnd="true" android:toYScale="1.0" />
android:layout_margin="16dp"/>
<Button rotate_anim.xml
android:id="@+id/buttonRotate" <?xml version="1.0" encoding="utf-8"?>
android:layout_width="wrap_content" <rotate
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/androi
android:text="Rotate" d"
android:layout_below="@id/buttonFade" android:duration="1000"
android:layout_alignParentStart="true" android:fromDegrees="0"
android:layout_margin="16dp"/> android:toDegrees="360"
<Button android:pivotX="50%"
android:id="@+id/buttonSlide" android:pivotY="50%" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slide"
android:layout_below="@id/buttonZoom"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"/>
</RelativeLayout>
MainActivity.java

package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private Button buttonFade, buttonZoom, buttonRotate, buttonSlide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
buttonFade = findViewById(R.id.buttonFade);
buttonZoom = findViewById(R.id.buttonZoom);
buttonRotate = findViewById(R.id.buttonRotate);
buttonSlide = findViewById(R.id.buttonSlide);
buttonFade.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
Animation fadeAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_animation);
imageView.startAnimation(fadeAnimation);}
});
buttonZoom.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
Animation zoomAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.zoom_animation);
imageView.startAnimation(zoomAnimation);
}
});
buttonRotate.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
Animation rotateAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.rotate_animation);
imageView.startAnimation(rotateAnimation);
}
});
buttonSlide.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
Animation slideAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_animation);
imageView.startAnimation(slideAnimation);
}
});
}
}

You might also like