一个不错的启动菜单显示屏动画效果
2013-07-01 16:24
330 查看
看到一个老外做的不错的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>
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>
定义了当进入和退出时的动画效果是什么。具体的再
在anim目录下分别有显示和消失的两个效果的XML具体定义:
appear.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="800"
/>
</set>
disppear.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="800"
/>
</set>
这里其实就是透明度的设置而已:
然后在manifest.xml中,设置好使用的样式:
<activity
android:name="SplashScreen"
android:theme="@style/Theme.Transparent"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
即可。
5 另外要注意的是,设置动画效果这段:
splashImageView.setBackgroundResource(R.drawable.flag);
final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
splashImageView.post(new Runnable(){
public void run() {
frameAnimation.start();
}
});
由于动画效果的设置不能在oncreate中直接设置,而是要从GUI线程中创建的,因此
使用imageview类的POST方法,当GUI创建时就显示这个动画
详细代码可以从附件下载
:
AdvancedSplashDemo.zip (1.2 MB)
下载次数: 555
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>
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>
定义了当进入和退出时的动画效果是什么。具体的再
在anim目录下分别有显示和消失的两个效果的XML具体定义:
appear.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="800"
/>
</set>
disppear.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="800"
/>
</set>
这里其实就是透明度的设置而已:
然后在manifest.xml中,设置好使用的样式:
<activity
android:name="SplashScreen"
android:theme="@style/Theme.Transparent"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
即可。
5 另外要注意的是,设置动画效果这段:
splashImageView.setBackgroundResource(R.drawable.flag);
final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
splashImageView.post(new Runnable(){
public void run() {
frameAnimation.start();
}
});
由于动画效果的设置不能在oncreate中直接设置,而是要从GUI线程中创建的,因此
使用imageview类的POST方法,当GUI创建时就显示这个动画
详细代码可以从附件下载
:
AdvancedSplashDemo.zip (1.2 MB)
下载次数: 555
相关文章推荐
- andriod一个不错的启动菜单显示屏动画效果
- andriod一个不错的启动菜单显示屏动画效果
- andriod一个不错的启动菜单显示屏动画效果
- andriod一个不错的启动菜单显示屏动画效果
- css3 做一个会动的菜单 menu 按钮动画效果
- 使用 JavaScript 创建一个带动画效果的固顶导航菜单
- 一个类似于android启动界面的动画效果
- 一个简单带动画效果tableview弹窗菜单
- 一个类似于android启动界面的动画效果
- 实现一个菜单的简单的动画效果
- 一个很酷的页面内导航菜单,有动画效果
- WPF中splashScreen启动程序之前出现一个过程动画的效果
- css3 做一个会动的菜单 menu 按钮动画效果
- 用jQuery和css3实现的一个模仿淘宝ued博客左边的菜单切换动画效果
- 一个不错的tab效果的导航菜单(一级和二级为横向)
- 自己写一个非常不错的Jquery动画效果,flash,Get out!
- 一个类似于android启动界面的动画效果
- 仿的一个动画菜单效果
- 一个不错的tab效果的导航菜单,事业单位适用!
- WPF中splashScreen启动程序之前出现一个过程动画的效果