您的位置:首页 > 移动开发 > Android开发

android 启动页

2015-11-24 17:59 423 查看
在android项目中一定存在的模块,一定是AppStart模块了。

分享代码如下:

package com.weidingqiang.custommooc;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

/**
* 启动页面
*/
public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();

private static final String First = "first";

private ImageView imageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_main);

imageView = (ImageView) this.findViewById(R.id.iconImageView);

initAnimation();
}

/**
* 初始化动画
*/
private void initAnimation(){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.start_anim);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
jump();
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
imageView.startAnimation(animation);
}

/**
* 动画完成
*/
private void jump(){
//查看是否第一次打开
//如果首次打开 则跳转到介绍页面
//否则直接进入主界面
SharedPreferences sharedPreferences= getSharedPreferences(TAG,
Activity.MODE_PRIVATE);
boolean isfrist = sharedPreferences.getBoolean(First, true);

Intent jumpintent = new Intent();

if(isfrist){
//第一次 运行介绍界面
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(First,false);
editor.commit();

}
else
{

}
startActivity(jumpintent);
finish();
}
}


布局文件为

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/loading_main_bg"
>

<ImageView
android:id="@+id/iconImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/loading_main_bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="30dp"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/copyright"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:textSize="10sp"
/>

</RelativeLayout>


动画文件为

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000">
<alpha android:fromAlpha="0.9" android:toAlpha="1.0"/>
</set>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: