android 项目学习随笔一(闪屏 )

1、取标题栏且全屏

<activity
android:name="com.ecollab.zhsh66.SplashActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

2、代码取掉标题

requestWindowFeature(Window.FEATURE_NO_TITLE);必须在setContentView(R.layout.activity_main);之前执行

3、整体旋转、缩放、渐变

public class SplashActivity extends Activity {

    private RelativeLayout rlRoot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        rlRoot = (RelativeLayout) findViewById(R.id.rl_root);
        // 旋转, 缩放, 渐变
        // 旋转
        RotateAnimation animRotate = new RotateAnimation(0, 360,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        animRotate.setDuration(1000);
        animRotate.setFillAfter(true);

        // 缩放
        ScaleAnimation animScale = new ScaleAnimation(0, 1, 0, 1,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        animScale.setDuration(1000);
        animScale.setFillAfter(true);

        // 渐变
        AlphaAnimation animAlpha = new AlphaAnimation(0, 1);
        animAlpha.setDuration(2000);
        animAlpha.setFillAfter(true);

        // 动画集合
        AnimationSet animSet = new AnimationSet(true);
        animSet.addAnimation(animRotate);
        animSet.addAnimation(animScale);
        animSet.addAnimation(animAlpha);

        rlRoot.startAnimation(animSet);

        animSet.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // 判断是否需要跳到新手引导
                boolean isGuideShow = PrefUtils.getBoolean("is_guide_show",
                        false, getApplicationContext());

                if (isGuideShow) {
                    // 动画结束后跳主页面
                    startActivity(new Intent(getApplicationContext(),
                            MainActivity.class));
                } else {
                    // 跳到新手引导
                    startActivity(new Intent(getApplicationContext(),
                            GuideActivity.class));
                }

                finish();
            }
        });
    }
}
View Code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash_bg_newyear" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/splash_horse_newyear" />

</RelativeLayout>
View Code

 

posted @ 2016-11-03 16:09  ecollab  阅读(359)  评论(1编辑  收藏  举报