編輯:Android開發實例
效果圖:
看到一個老外做的不錯的android啟動菜單的動畫效果,小結下。
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/TheSplashLayout"
- android:layout_gravity="center"
- >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/SplashImageView"
- android:layout_gravity="center"
- >
- </ImageView>
3 點啟動窗口動畫效果後顯示的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"
- />
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- </LinearLayout>
3 SplashScreen.java 這裡是歡迎啟動類的核心部分 ?
- public class SplashScreen extends Activity {
- /**
- * The thread to process splash screen events
- */
- private Thread mSplashThread; /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState); // Splash screen view
- setContentView(R.layout.splash);
- // Start animating the image
- final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
- splashImageView.setBackgroundResource(R.drawable.flag);
- final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
- splashImageView.post(new Runnable(){ public void run() {
- frameAnimation.start();
- }
- });
- final SplashScreen sPlashScreen = this;
- // The thread to wait for splash screen events
- mSplashThread = new Thread(){
- @Override
- public void run(){
- try {
- synchronized(this){
- // Wait given period of time or exit on touch
- wait(5000);
- }
- }
- catch(InterruptedException ex){
- }finish();
- // Run next activity
- Intent intent = new Intent();
- intent.setClass(sPlashScreen, MainActivity.class);
- startActivity(intent);
- stop();
- }
- };
- mSplashThread.start();
- }@Override
- public boolean onCreateOptionsMenu(Menu menu){
- super.onCreateOptionsMenu(menu);
- return false;
- }
- /**
- * Processes splash screen touch events
- */
- @Override
- public boolean onTouchEvent(MotionEvent evt)
- {
- if(evt.getAction() == MotionEvent.ACTION_DOWN)
- {
- synchronized(mSplashThread){
- mSplashThread.notifyAll();
- }
- }
- return true;
- }
4 為了更好看,在values 目錄下添加樣式文件styles.xml:
- <resources>
- <style name="Animations" parent="@android:Animation" />
- <style name="Animations.SplashScreen">
- <item name="android:windowEnterAnimation">@anim/appear</item>
- <item name="android:windowExitAnimation">@anim/disappear</item>
- </style>
- <style name="Theme.Transparent" parent="android:Theme">
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowIsFloating">true</item>
- <item name="android:backgroundDimEnabled">false</item>
- <item name="android:windowAnimationStyle">@style/Animations.SplashScreen</item>
- </style>
- </resources>
注意下這裡:
?
- <style name="Animations" parent="@android:Animation" />
- <style name="Animations.SplashScreen">
- <item name="android:windowEnterAnimation">@anim/appear</item>
- <item name="android:windowExitAnimation">@anim/disappear</item>
- </style>
源碼下載
本文實例講述了android編程實現懸浮窗體的方法。分享給大家供大家參考,具體如下: 突然對懸浮窗體感興趣,查資料做了個小Demo,效果是點擊按鈕後,關閉當前Ac
Android應用程序可以在許多不同地區的許多設備上運行。為了使應用程序更具交互性,應用程序應該處理以適合應用程序將要使用的語言環境方面的文字,數字,文件等。在本章中,我
JSON代表JavaScript對象符號。它是一個獨立的數據交換格式,是XML的最佳替代品。本章介紹了如何解析JSON文件,並從中提取所需的信息。Android提供了四個
Android系統默認的Toast十分簡潔,使用也非常的簡單。但是有時我們的程序使用默認的Toast時會和程序的整體風格不搭配,這個時候我們就需要自定義Toast