想在Android上为启动画面制作动画

时间:2011-11-25 10:17:16

标签: android

我希望在加载几秒钟后添加淡入和淡出到启动画面。是否有一个样本用于我的飞溅布局?

2 个答案:

答案 0 :(得分:17)

这是活动之间缓慢过渡的一个例子。您可以添加自己的动画:

public class OneActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.one);
        ((Button)findViewById(R.id.next_button)).setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                startActivity(new Intent(OneActivity.this, TwoActivity.class));
                overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
            }
        });
    }
}

<强> slide_in_left.xml:

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

<强> slide_out_left.xml:

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

淡入和淡出效果:

<!-- Fade out -->
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="300" />

<!-- Fade in -->
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="300" />

<!-- Slide in right and slide out right  -->
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="-100%p" android:toXDelta="0%p"
    android:duration="@android:integer/config_longAnimTime" />

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

另请参阅 Splash Fade, Activity Animations, overridePendingTransition

答案 1 :(得分:3)

是的,您可以向活动,视图等添加动画......

检查帖子 Animation Resources 以获得应用动画的想法。