Animation: fade in, fade out : Animation « Animation « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Animation » Animation 
Animation: fade in, fade out
    

package app.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

public class Test extends Activity implements View.OnClickListener {

    View viewToAnimate;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button button = (Button)findViewById(R.id.toggleButton);
        button.setOnClickListener(this);
        
        viewToAnimate = findViewById(R.id.theView);
    }
    
    @Override
    public void onClick(View v) {
        if(viewToAnimate.getVisibility() == View.VISIBLE) {
            Animation out = AnimationUtils.makeOutAnimation(this, true);
            viewToAnimate.startAnimation(out);
            viewToAnimate.setVisibility(View.INVISIBLE);
        else {
            Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
            viewToAnimate.startAnimation(in);
            viewToAnimate.setVisibility(View.VISIBLE);
        }
    }
}
//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <Button
    android:id="@+id/toggleButton"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Click to Toggle"
  />
  <View
    android:id="@+id/theView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#AAA"
  />
</LinearLayout>

   
    
    
    
  
Related examples in the same category
1.Frame based animation
2.extends Animation to create your own animation
3.Slide out down animation, bounce in down animation
4.XML for Fade in animation
5.Xml for Fade out animation
6.XML for slide out animation
7.Animation Cloning
8.Animation Loading
9.Multi Property Animation
10.Animation: push up in,push up out,push left in,push left out,fade in,fade out,hyperspace in,hyperspace out
11.Using AlphaAnimation class to do animation in code
12.Animation Interpolator
13.Using TranslateAnimation class
14.Demonstrates the seeking capability of ValueAnimator.
15.Animating by calling invalidate() from draw(),loading and drawing resources, handling onPause() in an animation
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.