andriod一个不错的启动菜单显示屏动画效果

看到一个老外做的不错的android启动菜单的动画效果,小结下。
1 首先在drawable目录下放一些动画要用的图片。
2 splash.xml:
复制代码
<?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> 
复制代码

 

4 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>
复制代码

详细源码下载


 

 

posted on   vus520  阅读(1021)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架

导航

< 2012年4月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
6 7 8 9 10 11 12
点击右上角即可分享
微信分享提示