Create the sample application that Rotate a green rectangle shape/image and after that double the size of that object and then shrink back to our starting size. - animation in android

No comments
Create the sample application that Rotate a green rectangle shape/image and after that double the size of that object and then shrink back to our starting size.

Program:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   
package="com.android.infiapps.myapplication10"
>

    <application
       
android:allowBackup="true"
       
android:icon="@mipmap/ic_launcher"
       
android:label="@string/app_name"
       
android:supportsRtl="true"
       
android:theme="@style/AppTheme"
>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/activity_main"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context="com.android.infiapps.myapplication10.MainActivity">



    <ImageView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_centerHorizontal="true"

        android:id="@+id/iv"

        android:layout_alignParentTop="true" />

</RelativeLayout>
MainActivity.java
package com.android.infiapps.myapplication10;



import android.graphics.Color;

import android.graphics.drawable.ShapeDrawable;

import android.graphics.drawable.shapes.RectShape;

import android.media.Image;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.ImageView;



public class MainActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        ImageView iv;

        iv=(ImageView)findViewById(R.id.iv);



        ShapeDrawable sd=new ShapeDrawable(new RectShape());

        sd.setIntrinsicHeight(100);

        sd.setIntrinsicWidth(200);

        sd.getPaint().setColor(Color.GREEN);

        iv.setImageDrawable(sd);



        Animation a= AnimationUtils.loadAnimation(this,R.anim.spin);

        iv.startAnimation(a);

    }

}
Output:

No comments :

Post a Comment