最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android項(xiàng)目實(shí)戰(zhàn)教程之高仿網(wǎng)易云音樂啟動頁實(shí)例代碼

 更新時(shí)間:2018年09月12日 15:16:32   作者:愛學(xué)啊  
這篇文章主要給大家介紹了關(guān)于Android項(xiàng)目實(shí)戰(zhàn)教程之高仿網(wǎng)易云音樂啟動頁的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

本文主要給大家介紹了關(guān)于Android高仿網(wǎng)易云音樂啟動頁的相關(guān)內(nèi)容,這一節(jié)我們來講解啟動界面,效果如下:


首次創(chuàng)建一個(gè)SplashActivity用來做啟動界面,因?yàn)閯?chuàng)建完項(xiàng)目默認(rèn)是MainActivity做主界面,所以需要去掉,將啟動配置到同時(shí)去掉SplashActivity,并且去掉SplashActivity的標(biāo)題欄,同時(shí)還要設(shè)置為全屏。

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,頂部一個(gè)ImageView讓他在水平居中,具頂部一個(gè)距離,這個(gè)距離大家可以按照自己的業(yè)務(wù)需求調(diào)整,然后放入一個(gè)TextView讓他在水平居中,垂直方向和父布局的底部對齊,同時(shí)設(shè)置一個(gè)Margin,接著放一個(gè)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暫時(shí)沒什么太多的邏輯,只是創(chuàng)建一個(gè)Handler,然后延時(shí)3秒鐘進(jìn)行下一步,然后在next方法中判斷是否需要顯示引導(dǎo)界面,是否登錄等:

public class SplashActivity extends BaseCommonActivity {

 //這樣創(chuàng)建有內(nèi)存泄漏,在性能優(yōu)化我們具體講解
 @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);
  //去除狀態(tài)欄
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

  setContentView(R.layout.activity_splash);
 }

 @Override
 protected void initDatas() {
  super.initDatas();
  //延時(shí)3秒,在企業(yè)中通常會有很多邏輯處理,所以延時(shí)時(shí)間最好是用3-消耗的的時(shí)間
  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);
  }
 }

 /**
  * 根據(jù)當(dāng)前版本號判斷是否需要引導(dǎo)頁
  * @return
  */
 private boolean isShowGuide() {
  return sp.getBoolean(String.valueOf(PackageUtil.getVersionCode(getApplicationContext())),true);
 }
}

當(dāng)前界面還可以增加倒計(jì)時(shí),廣告等內(nèi)容,這部分內(nèi)容我們在后面再講解。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論

安新县| 千阳县| 无锡市| 阳江市| 翁源县| 澎湖县| 巢湖市| 静海县| 绥宁县| 岚皋县| 枣庄市| 永福县| 密云县| 灵璧县| 湖口县| 蓬溪县| 长武县| 福安市| 东安县| 白玉县| 遵义县| 神木县| 宣化县| 镇沅| 克山县| 南召县| 马山县| 项城市| 桃江县| 沁阳市| 靖江市| 瑞昌市| 宁河县| 泾源县| 伊吾县| 天全县| 枝江市| 勃利县| 皮山县| 吉隆县| 武平县|