Need File:
1.SplashActivity.java
2.activity_splash.xml
3.res/anim/translate.xml
4.res/anim/alpha.xml
Step 1:
res/anim/alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="8000" />
Step 2:
res/anim/translate.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate xmlns:android="http://schemas.android.com/apk/res/android"android:fromXDelta="0%"android:toXDelta="0%"android:fromYDelta="200%"android:toYDelta="0%"android:duration="3000"android:zAdjustment="bottom" /></set>
Step 3:res/layout/activity_splash.xml<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout_anim" android:background="@android:color/white"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <ImageView android:id="@+id/image_logo" android:layout_width="150dp" android:layout_height="100dp" android:background="@drawable/logo"/> </LinearLayout> </LinearLayout>
Step 4:
public class SplashActivity extends Activity { Animation anim; private static int SPLASH_TIME_OUT = 5000; ImageView im_logo;
LinearLayout lay_anim;
public void onAttachedToWindow() { super.onAttachedToWindow(); Window window = getWindow(); window.setFormat(PixelFormat.RGBA_8888); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); im_logo=(ImageView)findViewById(R.id.image_logo);lay_anim=(LinearLayout)findViewById(R.id.layout_anim);StartAnimations(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i=new Intent(SplashActivity.this,LoginActivity.class); startActivity(i); finish(); } }, SPLASH_TIME_OUT); } private void StartAnimations() {
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
anim.reset();
lay_anim.clearAnimation(); lay_anim.startAnimation(anim );anim = AnimationUtils.loadAnimation(this, R.anim.alpha_anim); anim.reset(); im_logo.clearAnimation(); im_logo.startAnimation(anim);
} }
No comments:
Post a Comment