【邊做項目邊學Android】手機安全衛士01:splash介面ui

來源:互聯網
上載者:User

標籤:android   介面   

手機安全衛士項目是跟著黑馬的視頻做的。

splash是飛灑、飛濺的意思,主要是用於完成一個產品logo顯示,期間可以:

  1. 後台完成資料庫初始化的操作
  2. 連網訪問伺服器,擷取伺服器最新資訊(升級提示)
  3. 不同的日期顯示出來不同logo,判斷當前系統時間,素材一般從伺服器上下載下來.
  4. 判斷時間,根據不同時間顯示不同的載入頁面
布局檔案:splash.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@drawable/logo2"    android:gravity="center_horizontal"    android:orientation="vertical"    android:id="@+id/ll_splash_main"    >    <TextView        android:layout_marginTop="320dip"        android:id="@+id/tv_splash_version"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textColor="#FFff5f00"        android:textSize="20sp"        android:text="版本號碼"          />       <ProgressBar        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="20dip"        /></LinearLayout>

activity:SplashActivity
package com.liuhao.mobilesafe.ui;import com.liuhao.mobilesafe.R;import android.os.Bundle;import android.app.Activity;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.view.Menu;import android.view.Window;import android.view.WindowManager;import android.view.animation.AlphaAnimation;import android.widget.LinearLayout;import android.widget.TextView;public class SplashActivity extends Activity {private TextView tv_splash_version;private LinearLayout ll_splash_main;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);                //取消標題列        requestWindowFeature(Window.FEATURE_NO_TITLE);                setContentView(R.layout.splash);                tv_splash_version = (TextView) this.findViewById(R.id.tv_splash_version);        ll_splash_main = (LinearLayout) this.findViewById(R.id.ll_splash_main);                String versiontext = getVersion();        tv_splash_version.setText(versiontext);                /* AlphaAnimation類:透明度變化動畫類         * AlphaAnimation類是Android系統中的透明度變化動畫類,用於控制View對象的透明度變化,該類繼承於Animation類。         * AlphaAnimation類中的很多方法都與Animation類一致,該類中最常用的方法便是AlphaAnimation構造方法。         *          * public AlphaAnimation (float fromAlpha, float toAlpha)參數說明fromAlpha:開始時刻的透明度,取值範圍0~1。toAlpha:結束時刻的透明度,取值範圍0~1。         */        AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f);        aa.setDuration(2000); //Animation類的方法,設定期間         ll_splash_main.startAnimation(aa); //設定動畫                 //完成表單的全螢幕顯示        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.splash, menu);        return true;    }        /**     * 擷取當前程式的版本號碼     * @return     */    private String getVersion(){    // 擷取一個PackageManager的執行個體,從而可以擷取全域包資訊    PackageManager manager = getPackageManager();    try {    // Retrieve overall information about an application package that is installed on the system.PackageInfo info = manager.getPackageInfo(getPackageName(), 0);// The version name of this package, as specified by the <manifest> tag's versionName attribute.return info.versionName;} catch (Exception e) {e.printStackTrace();return "版本號碼未知";}        }    } 
相關知識點:

在開發程式是經常會需要軟體全螢幕顯示、自訂標題(使用按鈕等控制項)和其他的需求,今天這一講就是如何控制Android應用程式的表單顯示.

首先介紹一個重要方法那就是requestWindowFeature(featrueId),它的功能是啟用表單的擴充特性。參數是Window類中定義的常量。

一、枚舉常量

1.DEFAULT_FEATURES:系統預設狀態,一般不需要指定

2.FEATURE_CONTEXT_MENU:啟用ContextMenu,預設該項已啟用,一般無需指定

3.FEATURE_CUSTOM_TITLE:自訂標題。當需要自訂標題時必須指定。如:標題是一個按鈕時

4.FEATURE_INDETERMINATE_PROGRESS:不確定的進度

5.FEATURE_LEFT_ICON:標題列左側的表徵圖

6.FEATURE_NO_TITLE:無標題

7.FEATURE_OPTIONS_PANEL:啟用“選項面板”功能,預設已啟用。

8.FEATURE_PROGRESS:進度列指示器功能

9.FEATURE_RIGHT_ICON:標題列右側的表徵圖


default: DEFAULT_FEATURES

progress:FEATURE_PROGRESS:進度列指示器功能

no title:FEATURE_NO_TITLE:無標題


lefticon:FEATURE_LEFT_ICON:標題列左側的表徵圖


fullscreen:

indeterminate_progress: FEATURE_INDETERMINATE_PROGRESS:不確定的進度

customtitle:FEATURE_CUSTOM_TITLE:自訂標題。

AlphaAnimation類是Android系統中的透明度變化動畫類,用於控制View對象的透明度變化,該類繼承於Animation類。AlphaAnimation類中的很多方法都與Animation類一致,該類中最常用的方法便是AlphaAnimation構造方法。

【基本文法】public AlphaAnimation (float fromAlpha, float toAlpha)

參數說明

fromAlpha:開始時刻的透明度,取值範圍0~1。

toAlpha:結束時刻的透明度,取值範圍0~1。

運行

運行效果:

【邊做項目邊學Android】手機安全衛士01:splash介面ui

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.