Cdacians

Cdacians
Cdacians

Sunday, 26 February 2012

Wave Layout AnimationExample in Android


This example shows you how to create wave animation in grid layout.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it WaveLayoutAnimationExample.
2.) Create and open res/anim/layout_wave_scale.xml file and write following code:
<?xml version="1.0" encoding="utf-8"?>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
       android:rowDelay="75%"
       android:columnDelay="0%"
       android:directionPriority="none"
       android:animation="@anim/wave_scale" />
3.) Create and open res/anim/wave_scale.xml file and write following code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_interpolator">
        <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
                android:duration="100" />
        <scale android:fromXScale="0.5" android:toXScale="1.5"
                android:fromYScale="0.5" android:toYScale="1.5"android:pivotX="50%"
                android:pivotY="50%" android:duration="200" />
        <scale android:fromXScale="1.5" android:toXScale="1.0"
                android:fromYScale="1.5" android:toYScale="1.0"android:pivotX="50%"
                android:pivotY="50%" android:startOffset="200"android:duration="100" />
</set>
4.) Write following into main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid" android:layoutAnimation="@anim/layout_wave_scale"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:verticalSpacing="10dp" android:horizontalSpacing="10dp"
        android:numColumns="auto_fit" android:columnWidth="60dp"
        android:stretchMode="columnWidth" android:gravity="center" />
5.) Run for output.
Steps:
1.) Create a project named WaveLayoutAnimationExample and set the information as stated in the image.
Build Target: Android 2.1
Application Name: WaveLayoutAnimationExample
Package Name: com.example. WaveLayoutAnimation
Activity Name: WaveLayoutAnimationActivity
Min SDK Version: 7
2.) Open WaveLayoutAnimationActivity.java file and write following code there:
package com.example.WaveLayoutAnimation;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class WaveLayoutAnimationActivity extends Activity {
    private List<ResolveInfo> mApps;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent mainIntent = new Intent(Intent.ACTION_MAINnull);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
        setContentView(R.layout.main);
        GridView grid = (GridView) findViewById(R.id.grid);
        grid.setAdapter(new AppsAdapter());
    }
    public class AppsAdapter extends BaseAdapter {
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(WaveLayoutAnimationActivity.this);
            ResolveInfo info = mApps.get(position % mApps.size());
            i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));
            i.setScaleType(ImageView.ScaleType.FIT_CENTER);
            i.setLayoutParams(new GridView.LayoutParams(36, 36));
            return i;
        }
        public final int getCount() {
            return Math.min(32, mApps.size());
        }
        public final Object getItem(int position) {
            return mApps.get(position % mApps.size());
        }
        public final long getItemId(int position) {
            return position;
        }
    }
}
3.) Compile and build the project.
4.) This application will show icon of all the application available into your apps folder or available into category_launcher.
Output


Thanks
akm
www.cdacians.com

No comments:

Post a Comment