Saturday, August 24, 2013

Android ViewAnimator Example

ViewAnimator 
A ViewAnimator  is used to animate or switch between the screens.
In this tutorial I will show how to use ViewAnimator  to switch between screen with Animation.

ViewAnimator Example


main.xml


Android ViewAnimator





<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/LinearLayout01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true" >

        <ViewAnimator
            android:id="@+id/viewAnimator1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

<ImageView
android:id="@+id/imageView1"
android:src="@drawable/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>

<Button
android:id="@+id/button"
android:text="This Is My Button"
android:layout_gravity="center_vertical"
android:textSize="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>

<ImageView
android:id="@+id/imageView2"
android:src="@drawable/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>

<TextView
android:id="@+id/textView1"
android:text="        This Is  My Text "
android:textSize="30dp"
android:textColor="#0000FF"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>                                  
               
            </ViewAnimator>
           
        </LinearLayout>
       
        <LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="400dp" >
   <Button
       android:id="@+id/buttonNext"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Previous" />

   <Button
       android:id="@+id/buttonPrevious"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="  Next  " />
    </LinearLayout>


</RelativeLayout>


MainActivity.java


public class MainActivity extends Activity
{

Button btnNext,btnPrevious;
ViewAnimator viewAnimator;
 
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
     
viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator1);

final Animation inAnim = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
final Animation outAnim = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right);
 
viewAnimator.setInAnimation(inAnim);
viewAnimator.setOutAnimation(outAnim);
     
viewAnimator.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
viewAnimator.showNext();
}
});
     
Button btn1 = (Button) findViewById(R.id.buttonNext);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
viewAnimator.showPrevious();
}
});
     
Button btn2 = (Button) findViewById(R.id.buttonPrevious);
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
viewAnimator.showNext();
}
});      
   
    }
}


Android ViewAnimator

Android ViewAnimator

ViewAnimator


 

New Advance Topics:                   Android LiveWallpaer Tutorial
Android ImageSwitcher                    Android TextSwitcher                                Android ViewFlipper
Android Gesture Detector               Handling/Detecting Swipe 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
Android TextWatcher                               Android ExpandableListView

 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 Advance Views
Android Spinner                                                                           Android GalleryView
Android TabWidget                                                                      Android ExpandableListView

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
How to Hide Title Bar In Android
How to show an Activity in Landscape or Portrait Mode only.
How to Set an Image as Wallpaper.






No comments:

Post a Comment