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

所属分类: 软件编程 / Android 阅读数: 82
收藏 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网络编程之获取网络上的Json数据实例

这篇文章主要介绍了Android网络编程之获取网络上的Json数据实例,本文用完整的代码实例讲解了在Android中读取网络中Json数据的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中的windowSoftInputMode属性详解

这篇文章主要介绍了Android中的windowSoftInputMode属性详解,本文对windowSoftInputMode的9个属性做了详细总结,需要的朋友可以参考下
收藏 0 赞 0 分享

Android网络编程之UDP通信模型实例

这篇文章主要介绍了Android网络编程之UDP通信模型实例,本文给出了服务端代码和客户端代码,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中使用ListView实现漂亮的表格效果

这篇文章主要介绍了Android中使用ListView实现漂亮的表格效果,本文用详细的代码实例创建了一个股票行情表格,需要的朋友可以参考下
收藏 0 赞 0 分享

Android中刷新界面的二种方法

这篇文章主要介绍了Android中刷新界面的二种方法,本文使用Handler、postInvalidate两种方法实现界面刷新,需要的朋友可以参考下
收藏 0 赞 0 分享

Android SDK三种更新失败及其解决方法

这篇文章主要介绍了Android SDK三种更新失败及其解决方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(一)

Android3.0(API level 11)开始,Android设备不再需要专门的菜单键。随着这种变化,Android app应该取消对传统6项菜单的依赖。取而代之的是提供anction bar来提供基本的用户功能
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(二)

这次将继续上一篇文章没有讲完的Menu的学习,上下文菜单(Context menu)和弹出菜单(Popup menu)
收藏 0 赞 0 分享

Android学习笔记——Menu介绍(三)

今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习,需要的朋友可以参考下
收藏 0 赞 0 分享

Android显示网络图片实例

这篇文章主要介绍了Android显示网络图片的方法,以实例形式展示了Android程序显示网络图片的方法,非常具有实用价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多