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

所属分类: 软件编程 / Android 阅读数: 98
收藏 0 赞 0 分享

前言

本文主要给大家介绍了关于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);
 }
}

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

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

更多精彩内容其他人还在看

Android样式和主题之选择器的实例讲解

今天小编就为大家分享一篇关于Android样式和主题之选择器的实例讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
收藏 0 赞 0 分享

Android应用动态修改主题的方法示例

今天小编就为大家分享一篇关于Android应用动态修改主题的方法示例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
收藏 0 赞 0 分享

Flutter 网络请求框架封装详解

这篇文章主要介绍了Flutter 网络请求框架封装详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Flutter倒计时/计时器的实现代码

这篇文章主要介绍了Flutter倒计时/计时器的实现代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Android使用google breakpad捕获分析native cash

这篇文章主要介绍了Android使用google breakpad捕获分析native cash 的相关知识,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

详解Flutter WebView与JS互相调用简易指南

这篇文章主要介绍了详解Flutter WebView与JS互相调用简易指南,分为JS调用Flutter和Flutter调用JS,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android开发实现ListView和adapter配合显示图片和文字列表功能示例

这篇文章主要介绍了Android开发实现ListView和adapter配合显示图片和文字列表功能,涉及Android使用ListView结合adapter适配器实现图文显示功能相关的布局、解析、权限控制等操作技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

Android文字基线Baseline算法的使用讲解

今天小编就为大家分享一篇关于Android文字基线Baseline算法的使用讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
收藏 0 赞 0 分享

Flutter自定义实现神奇动效的卡片切换视图的示例代码

这篇文章主要介绍了Flutter自定义实现神奇动效的卡片切换视图的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Android实现自定义滑动刻度尺方法示例

这篇文章主要给大家介绍了关于Android实现自定义滑动刻度尺的相关资料,文中通过示例代码介绍的非常详细,对各位Android开发者们具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享
查看更多