Android APP 开始的动画效果

来源:互联网 发布:湘北vs山王球员数据 编辑:程序博客网 时间:2024/06/10 23:58

一般的APP 在启动的时候都有一个欢迎页面,看起来非常的高大上,而且很绚丽,本篇讲述一个使用渐变效果的开始页面

首先是布局页面,这儿我在上面放了一个关闭按钮,有的人可能不喜欢这个动画,就可以关闭,直接进入APP 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/start_background"
    android:gravity="bottom"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/start_background"
        android:layout_weight="1.00" >


        <ImageButton
            android:id="@+id/btn_close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginRight="18dp"
            android:layout_marginTop="18dp"
            android:background="#00000000"
            android:src="@drawable/abc_ic_clear_mtrl_alpha" />


    </RelativeLayout>


</LinearLayout>

布局完成就设置它的事件,设定一个时间让欢迎页面展示,展示 晚了就关闭这个Activity并启动指定的Activity

package com.example.show;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageButton;


public class StartActivity extends Activity implements OnClickListener
{

private ImageButton btn_close;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final View view = View.inflate(this, R.layout.start, null);
        setContentView(view);
        
        btn_close = (ImageButton) findViewById(R.id.btn_close);
        btn_close.setOnClickListener(this);
                                                                      
        //渐变展示启动屏
        AlphaAnimation start = new AlphaAnimation(0.3f,1.0f);
        start.setDuration(5000);
        view.startAnimation(start);
        start.setAnimationListener(new AnimationListener()
        {
            @Override
            public void onAnimationEnd(Animation arg0) {
                redirectTo();
            }
            @Override
            public void onAnimationRepeat(Animation animation) {
           
            }
            @Override
            public void onAnimationStart(Animation animation) {}
                                                                          
        });
                                                          
    }
    /**
     * 跳转到...
     */
    private void redirectTo()
    {       
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
@Override
public void onClick(View v) 
{
if (v.getId() == R.id.btn_close)
{
Intent intent = new Intent(this, MainActivity.class);
       startActivity(intent);
       finish();
}

}
}


0 0
原创粉丝点击