国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android項目實戰教程之高仿網易云音樂啟動頁實例代碼

2019-10-21 21:38:54
字體:
來源:轉載
供稿:網友

前言

本文主要給大家介紹了關于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"  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); }}

當前界面還可以增加倒計時,廣告等內容,這部分內容我們在后面再講解。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 密山市| 华容县| 舟山市| 当雄县| 秦皇岛市| 呼图壁县| 博罗县| 和田市| 连江县| 平顶山市| 信阳市| 太白县| 金山区| 永宁县| 红桥区| 厦门市| 陇西县| 五华县| 泰安市| 深州市| 贡嘎县| 沙洋县| 榕江县| 金华市| 吐鲁番市| 和平县| 平舆县| 扶沟县| 罗山县| 山东省| 随州市| 瑞昌市| 巴林右旗| 庆安县| 阳城县| 印江| 新化县| 奇台县| 泰和县| 玉环县| 洱源县|