編輯:關於 Android 程式設計
LinearLayout 是 Android 中最常用的版面配置之一,它會將所包含的子元素沿著單一方向排列。方向可分為水平與垂直兩種,透過 android:orientation="vertical" 或 android:orientation="horizontal" 來設定,所有元素都會一個接著一個依序排列。
若採垂直排列,子元素會從上到下依序堆疊;若採水平排列,則會從左到右依序展開。以下以一個簡單的 LayoutDemo 為例說明。
執行效果:

版面配置檔 main.xml:
<?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" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="RelativeLayout 的使用" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="FrameLayout 的使用" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TableLayout 的使用" />
</LinearLayout>
Java 原始碼 MainActivity.java:
package com.rainsong.layoutdemo;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
由此可見,只要透過 LinearLayout 的 orientation 屬性,就能輕鬆完成垂直或水平方向的元素排列,是入門 Android 版面配置的良好起點。
Android Paint setXfermode() 方法講解
看過很多開源代碼的實現效果,發現裡面很多地方都用到了這個函數,於是想花些時間研究一下。我現在寫博客一般不可能一下子寫完,因為我也要查資料、寫代碼去驗證效果,還要找一些好的
Android 實現指針滑動動態效果的方法
要做出一個像儀表指針般平滑移動的動態效果,可以透過 FrameLayout 疊放指針與刻度,再開啟一條執行緒,利用迴圈與休眠來控制指針的 padding 屬性,藉此產生移
Android 捕獲並攔截 TextView 超連結點擊的方法
本文分享如何捕獲 TextView 中的超連結點擊事件,希望能對大家有所幫助。所謂捕獲 TextView 超連結,指的是當一段文字裡含有網址時,TextView 會把它以
Android Studio 下去不掉標題欄?三種解法與背後的原因
在 Eclipse 時代,要拿掉 Activity 的預設標題欄,我習慣寫這一行: requestWindowFeature(Window.FEATURE_NO_TIT