Saturday, June 22, 2013

GridView Animation In Android

The Android Development Tutorials blog contains Basic as well as Advanced android tutorials.Go to Android Development Tutorials to get list of all Android Tutorials.

GridView



In Android we can animate a GridView  to make it more interactive and enhance the user experience.

To animate a GridView we need animation resource.

In this Example I have used two types of Animation.
Type 1: GridView will come In on Screen from  Top Left corner. (fly_in_from_top_corner.xml has been used for this)  See Snapshot 1 below
Type 2: GridView will come In on Screen from  Center of the Screen.(fly_in_from_center.xml has been used for this)  See Snapshot 2 below

To learn Basic of Android Animation  go to  Android Animation Tutorial

Animation  Resources

 fly_in_from_top_corner.xml


<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
    <scale android:interpolator="@android:anim/decelerate_interpolator"
           android:fromXScale="0.0" android:toXScale="1.0"
           android:fromYScale="0.0" android:toYScale="1.0"
           android:pivotX="100%" android:pivotY="0%"
           android:fillAfter="false" android:duration="5000"/>
</set>


 fly_in_from_center.xml


<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
    <scale android:interpolator="@android:anim/decelerate_interpolator"
           android:fromXScale="1.0" android:toXScale="0.0"
           android:fromYScale="1.0" android:toYScale="0.0"
           android:pivotX="50%" android:pivotY="50%"
           android:fillAfter="false" android:duration="1000"/>
</set>


Create a new Folder "anim" inside  "res" folder and put these two animation resource files in "anim" folder

main.xml


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#4D9494"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <GridView
        android:id="@+id/gridView"
        android:verticalSpacing="5dp"
        android:horizontalSpacing="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:numColumns="3" >
    </GridView>

</LinearLayout>



GridView
                                                             Snapshot 1: GridView is Coming from Top Corner


GridView
                                                                  Snapshot 2: GridView is Coming from Center



GridViewActivity 

 

public class MainActivity extends Activity
{
   
     static final String[] numbers = new String[] {
           "A", "B", "C", "D", "E",
           "F", "G", "H", "I", "J",
           "K", "L", "M", "N", "O",
           "P", "Q", "R", "S", "T",
           "U", "V", "W", "X", "Y", "Z"};

   
             GridView gridView;
            @Override
            protected void onCreate(Bundle savedInstanceState)
            {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.main);
                       
                        gridView=(GridView)findViewById(R.id.gridView);
                       
                        // Create the ArrayAdapter
                        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                                android.R.layout.simple_list_item_1, numbers);
                       
                        // Set the Adapter to GridView
                        gridView.setAdapter(adapter);
                           
                        // Set the Required Animation to GridView and start the Animation

                        // use fly_in_from_center to have 2nd type of animation effect (snapshot 2)
                        Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fly_in_from_top_corner);
                        gridView.setAnimation(anim);
                        anim.start()
;
            }
   
}




GridView

 


New Advance Topics:                   Android LiveWallpaer Tutorial
Android ImageSwitcher                    Android TextSwitcher                                Android ViewFlipper
Android Gesture Detector               Handling/Detecting Swap Events                Gradient Drawable
Detecting Missed Calls                    Hide Title Bar                                           GridView Animation
Android AlarmManager                 Android BootReceiver                       Vibrate Phone In a Desirable Pattern    
Developing for Different Screen Sizes           Showing Toast for Longer Time       Publishing your App
How to publish Android App on Google Play

 Beginning With Android
      Android : Introduction(What is Android)                                                 Configuring Eclipse for Android Development
     Creating Your First Android Project                                           Understanding Android Manifest File of your android app

 Advance Android Topics                                                              Customizing Android Views


Working With Layouts                                                                Working With Views

Understanding Layouts in Android                                                   Using Buttons and EditText in Android
Working with Linear Layout (With Example)                                     Using CheckBoxes in Android
Nested Linear Layout (With Example)                                              Using AutoCompleteTextView in Android                                                                                          Grid View
Relative Layout In Android                                                               ListView
Table Layout                                                                                   Android ProgressBar
Frame Layout(With Example)                                                          Customizing ProgressBar
Absolute Layout                                                                             Customizing Radio Buttons
Grid Layout                                                                                    Customizing Checkboxes In Android

Android Components                                                                 Dialogs In Android

Activity In Android                                                                    Working With Alert Dialog
Activity Life Cycle                                                                    Adding Radio Buttons In Dialog
Starting Activity For Result                                                       Adding Check Boxes In Dialog
Sending Data from One Activity to Other in Android                    Creating Customized Dialogs in Android
Returning Result from Activity                                                   Creating Dialog To Collect User Input
Android : Service                                                                     DatePicker and TimePickerDialog
BroadcastReceiver                                                                   Using TimePickerDialog and DatePickerDialog In android

Menus In Android                                                                ListView:
Creating Option Menu                                                               Populating ListView With DataBase
Creating Context Menu In Android                                              Populating ListView with ArrayList
                                                                                               ListView with Custom Adapter

Toast                                                                                      Working With SMS
Customizing Toast In Android                                                       How to Send SMS in Android
Customizing the Display Time of Toast                                        How To Receive SMS
Customizing Toast At Runtime                                                  Accessing Inbox In Android
Adding Image in Toast
Showing Toast for Longer Time


TelephonyManager                                                            Storage: Storing Data In Android
Using Telephony Manager In Android                                          SharedPreferences In Android
                                                                                              Reading and Writing files to Internal Stoarage

Working With Incoming Calls                                       DataBase :  Introduction of SQLiteDataBase
How To Handle Incoming Calls in Android                                Working With Database in Android
How to Forward an Incoming Call In Android                            Creating Table In Android
CALL States In Android                                                          Inserting, Deleting and Updating Records In Table in Android


Miscellaneous
Notifications In Android
How To Vibrate The Android Phone
Sending Email In Android
Opening a webpage In Browser
How to Access PhoneBook In Android
Prompt User Input with an AlertDialog







1 comment:

  1. android.R.layout.simple_list_item_1
    where its layout

    ReplyDelete