温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android项目实战教程之高仿网易云音乐启动页实例代码

发布时间:2020-09-07 12:16:01 来源:脚本之家 阅读:249 作者:爱学啊 栏目:移动开发

前言

本文主要给大家介绍了关于Android高仿网易云音乐启动页的相关内容,这一节我们来讲解启动界面,效果如下:

Android项目实战教程之高仿网易云音乐启动页实例代码

首次创建一个SplashActivity用来做启动界面,因为创建完项目默认是MainActivity做主界面,所以需要去掉,将启动配置到同时去掉SplashActivity,并且去掉SplashActivity的标题栏,同时还要设置为全屏。

Activity启动配置

在清单文件将启动配置剪贴到SplashActivity:

<activity
 android:name=".activity.SplashActivity"
 android:screenOrientation="portrait"
 android:theme="@style/NoActionBar">
 <intent-filter>
  <action android:name="android.intent.action.MAIN" />

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

布局的话可以说是很简单了,最外层使用RelativeLayout,顶部一个ImageView让他在水平居中,具顶部一个距离,这个距离大家可以按照自己的业务需求调整,然后放入一个TextView让他在水平居中,垂直方向和父布局的底部对齐,同时设置一个Margin,接着放一个ImageView用来显示Logo,让他在TextView的上方就行了:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.ixuea.android.courses.music.activity.SplashActivity">

 <ImageView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_alignParentLeft="true"
  android:layout_alignParentStart="true"
  android:layout_alignParentTop="true"
  android:scaleType="centerCrop"
  android:src="@drawable/splash_bg" />

 <ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentTop="true"
  android:layout_centerHorizontal="true"
  android:layout_marginTop="130dp"
  android:src="@drawable/splash_banner" />

 <ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_above="@+id/tv_copyright"
  android:layout_centerHorizontal="true"
  android:src="@drawable/splash_logo" />

 <TextView
  android:id="@+id/tv_copyright"
  
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:layout_centerHorizontal="true"
  android:layout_marginBottom="20dp"
  android:layout_marginTop="10dp"
  android:text="Copyright © 2018 Ixuea. All Rights Reserved" />
</RelativeLayout>

Activity暂时没什么太多的逻辑,只是创建一个Handler,然后延时3秒钟进行下一步,然后在next方法中判断是否需要显示引导界面,是否登录等:

public class SplashActivity extends BaseCommonActivity {

 //这样创建有内存泄漏,在性能优化我们具体讲解
 @SuppressLint("HandlerLeak")
 private Handler mHandler = new Handler() {
  @SuppressWarnings("unused")
  public void handleMessage(Message msg) {
   next();
  }
 };

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  //去除状态栏
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

  setContentView(R.layout.activity_splash);
 }

 @Override
 protected void initDatas() {
  super.initDatas();
  //延时3秒,在企业中通常会有很多逻辑处理,所以延时时间最好是用3-消耗的的时间
  mHandler.postDelayed(new Runnable() {
   @Override
   public void run() {
    mHandler.sendEmptyMessage(-1);
   }
  }, 3000);
 }

 private void next() {
  if (isShowGuide()) {
   startActivityAfterFinishThis(GuideActivity.class);
  } else if (sp.isLogin()) {
   startActivityAfterFinishThis(MainActivity.class);
  } else {
   startActivityAfterFinishThis(LoginActivity.class);
  }
 }

 /**
  * 根据当前版本号判断是否需要引导页
  * @return
  */
 private boolean isShowGuide() {
  return sp.getBoolean(String.valueOf(PackageUtil.getVersionCode(getApplicationContext())),true);
 }
}

当前界面还可以增加倒计时,广告等内容,这部分内容我们在后面再讲解。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI