Thursday 13 June 2013

animated splash screen

1)create a java file name NewSplashScreen.java
=========================

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

public class NewSplashScreen extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xnewsplashscreen);
        thread.start();          
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
   private Thread thread = new Thread()
   {
    public void run()
    {

                    RunAnimations();
                    SystemClock.sleep(3000);
                    Intent iv = new Intent(NewSplashScreen.this,MainActivity.class);                  
                    startActivity(iv);
                    finish();
    }
   };
    private void RunAnimations() {
        Animation topout = AnimationUtils.loadAnimation(this, R.anim.animationtopout);
        LinearLayout ltop=(LinearLayout)findViewById(R.id.lyttop);
        ltop.startAnimation(topout);
     
        Animation bottoout = AnimationUtils.loadAnimation(this, R.anim.animationbottomout);
        LinearLayout lbottom=(LinearLayout)findViewById(R.id.lytbottom);
        lbottom.startAnimation(bottoout);
    }
}
2)create newsplashscreen.xml
==============

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
 android:background="@drawable/contact_littlebuddha">
     <LinearLayout
      android:id="@+id/lyttop"
      android:layout_weight="1"
      android:background="@drawable/top_part"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">       
     </LinearLayout>     
     <LinearLayout
       android:id="@+id/lytbottom" 
       android:layout_weight="1"
       android:background="@drawable/bottom_part"
       android:layout_marginTop="-25dip"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">                
      </LinearLayout>      

</LinearLayout>

3)animationtopout.xml
==============

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromXDelta="0%"
  android:toXDelta="0%"
  android:fromYDelta="0%"
  android:toYDelta="-100%"
  android:duration="3000"
 />

4)animationbottomout.xml
=============

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromXDelta="0%"
  android:toXDelta="0%"
  android:fromYDelta="0%"
  android:toYDelta="100%"
  android:duration="3000"
 />

No comments:

Post a Comment