当前位置: 移动技术网 > IT编程>移动开发>Android > Android项目实战教程之高仿网易云音乐启动页实例代码

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

2019年08月02日  | 移动技术网IT编程  | 我要评论

aotm奥特曼动画片,世纪宝鼎的象征意义,贾南

前言

本文主要给大家介绍了关于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"
  style="@style/copyrighttext"
  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);
 }
}

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

总结

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网