編輯:關於 Android 開發
本文將實現從 Splash 界面進入 Home 界面時的漸進淡入動畫效果,並逐步搭建 Home 界面的標題欄。
在 onCreate 中調用 initAnimation() 方法,通過 AlphaAnimation 實現透明度從 0 到 1 的漸變:
/**
* 添加淡入的動畫效果
*/
private void initAnimation() {
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(3000);
rl_root.startAnimation(alphaAnimation);
}
其中 rl_root 在類中定義:
private RelativeLayout rl_root;
它對應 Splash 界面相對布局的 id:android:id="@+id/rl_root",並在初始化 UI 的方法中完成綁定:
/**
* 初始化 UI 方法
*/
private void initUI() {
tv_version_name = (TextView) findViewById(R.id.tv_version_name);
rl_root = (RelativeLayout) findViewById(R.id.rl_root);
}
這樣便實現了 Splash 界面的淡入效果。
先實現最簡單的標題欄,效果如下:

代碼如下:
<TextView android:text="功能列表" android:gravity="center" android:textSize="20sp" android:textColor="#000" android:padding="10dp" android:background="#0f0" android:layout_width="match_parent" android:layout_height="wrap_content" />
由於標題欄樣式非常常用,將其抽取為樣式便於復用。在 style.xml 中添加:
<style name="TitleStyle"> <item name="android:gravity">center</item> <item name="android:textSize">20sp</item> <item name="android:textColor">#000</item> <item name="android:padding">10dp</item> <item name="android:background">#0f0</item> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> </style>
之後在 activity_home.xml 中只需一行即可引用:
<TextView android:text="功能列表" style="@style/TitleStyle" />
Android Log 使用指南:日誌方法、Logcat 與 Live Template
Android Log 簡介 Android 提供 android.util.Log 類別,用來輸出除錯訊息。常見方法包括 v、d、i、w、e,分別代表不同層級。開發時可
Android App 代碼混淆實戰:從開啟、打包到錯誤還原
Android App 代碼混淆實戰:從開啟、打包到錯誤還原 接到現有專案的混淆需求時,最常遇到的問題不是「怎麼開啟」,而是「哪些類別不能混淆」。本文以一個實際案例說明
解決AIDL使用時報錯找不到自定義資料類型的問題
解決AIDL使用時報錯找不到自定義資料類型的問題 在研究Android多進程編程時,我照著書敲了一個AIDL範例。其中用Android Studio自動生成了AIDL檔案
Android JSON 解析:從 JSONObject 到具體物件
Android JSON 解析:從 JSONObject 到具體物件在 Android 網路應用中,伺服器常以 JSON 格式回傳資料。Android 內建 JSONOb