編輯:關於 Android 開發
Android 中有三個經常使用的布局容器:LinearLayout、RelativeLayout 與 TableLayout。本文先從最基礎的 LinearLayout(線性布局)談起。
LinearLayout 會讓其中的組件或子容器沿水平或垂直方向線性排列。它有幾個基本屬性值得掌握:
android:orientation:值為 horizontal 時水平排列,值為 vertical 時垂直排列。android:layout_width 與 android:layout_height:控制每個組件的寬與高。android:layout_weight:控制組件之間的比例分配。android:layout_gravity:控制組件的對齊與排列方式。android:padding:設定內部的邊緣間距。以下是一個簡單的 LinearLayout XML 文件,示範了如何在線性容器中嵌套 RadioGroup 與 RadioButton:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="https://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px">
<RadioButton
android:text="RadioButton1" />
<RadioButton
android:text="RadioButton2" />
</RadioGroup>
<RadioGroup
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5px">
<RadioButton
android:text="RadioButton1" />
<RadioButton
android:text="RadioButton2" />
<RadioButton
android:text="RadioButton3" />
</RadioGroup>
</LinearLayout>
透過 LinearLayout,我們可以輕鬆地將介面元素排列成整齊的水平或垂直隊列,是建構 Android 界面的基礎配置。掌握它之後,再搭配 RelativeLayout 與 TableLayout,就能應對更複雜的布局需求。
Android Studio 快速產出 .so:從 Native Support 到 jniLibs 的完整流程
從此告別指令行 以前在 Eclipse 時代要編一個 .so,得先架 GNUstep 模擬 Linux 環境,再敲一堆指令,流程繁瑣又容易卡住。Android Studi
Android 打造炫酷導航欄:ViewPager 指示器、反彈滾動與圖示旋轉
從普通導航欄到動態互動 很多 App 的頂部導航欄只是靜態文字,但若加入滑動指示器、左右反彈與圖示旋轉,就能讓操作更有趣。本文以仿新聞閱讀器的風格,說明如何自訂 View
Android 應用程序簽名詳解:作用、Eclipse 操作與命令行實踐
Android 應用程序簽名詳解:作用、Eclipse 操作與命令行實踐 簽名 Android 應用程序 Android 應用以包名作為唯一標識。如果同一部手機上安裝兩個
Android 開發技巧:自訂仿微信圖片裁剪控制項
Android 開發技巧:自訂仿微信圖片裁剪控制項 在設定頭像或上傳圖片時,拍照或選圖後通常都需要進行裁剪。若希望做出類似微信的裁剪體驗,重點在於讓使用者拖動與縮放圖片,