編輯:關於 Android 程式設計
在打造 Android 登入介面時,有幾個實務上經常踩到的細節值得先記住:圖片資源盡量放在 drawable 一級目錄下,且檔案命名只能使用小寫字母、數字與底線;此外,若希望介面呈現乾淨的沉浸式效果,往往需要隱藏應用標題列並讓內容全螢幕覆蓋。
以下先來看佈局的核心寫法。這裡大量運用 layout_weight 搭配 layout_height="0dp" 的技巧,讓各區塊依比例分配垂直空間,這正是「紅線處按比例設置」的關鍵:
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/home_page_bg"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center" ></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center_horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/home_page_login" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/home_page_register"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:background="@drawable/button01_a" />
<Button android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:background="@drawable/button02_a" />
<Button android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:background="@drawable/button03_a" />
<Button android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:background="@drawable/button04_a" />
<Button android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1" android:background="@drawable/button05_a" />
</LinearLayout>
</LinearLayout>
上方幾個區塊皆以 layout_weight="1" 平均瓜分剩餘空間,讓登入與註冊按鈕能置中呈現;最底下一列的五個按鈕則各自帶 layout_weight="1",配合寬度設為 0dp,實現等寬平分的效果。至於「介面不顯示應用名稱」與「全螢幕覆蓋」的設定,可透過在 Style 中關閉標題列、或於 Activity 的 onCreate 中呼叫 requestWindowFeature(Window.FEATURE_NO_TITLE) 來達成。

加入購物車動畫實作:用貝茲曲線讓商品沿拋物線飛入
效果預覽 參考方向:Android 補間動畫與屬性動畫都能做到類似效果,本文採用後者搭配貝茲曲線。 實作思路 先確定動畫的起點與終點; 在起點與終點之間,用二次貝茲曲
Android 開源源碼:火車車次與航班資訊查詢(含收藏功能)
本專案示範一個同時支援火車車次與航班查詢的 Android 應用,輸入出發城市與目的地城市後即可列出對應班次,查詢結果可加入收藏清單以便日後快速查閱。車次與航班資料由 w
Android 屬性動畫初見:ValueAnimator、ObjectAnimator 與 AnimatorSet
本節引言 Android 動畫主要可分為幀動畫、補間動畫與屬性動畫。本篇聚焦屬性動畫,說明它如何直接操作物件屬性,產生更自然的動畫效果。 1. ValueAnimato
jadx:一款強大的 Android APK 反編譯利器
從一次遺漏說起 在上一篇對比 Android ClassyShark 與 ApkTool 的文章中,感謝讀者 @weishu 的提醒,讓我意識到自己漏掉了一個非常好用的