Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 資訊

Android 控件布局屬性整理與速查

編輯:Android 資訊

Android 的介面排版依賴大量布局屬性,這些屬性會影響控制項的位置、大小、對齊與間距。本文將常見屬性做分類整理,方便開發時快速查閱。

RelativeLayout 常用定位屬性

  • android:layout_centerHorizontal:水平居中。
  • android:layout_centerVertical:垂直居中。
  • android:layout_centerInParent:相對於父容器完全居中。
  • android:layout_alignParentTop:貼齊父容器頂部。
  • android:layout_alignParentBottom:貼齊父容器底部。
  • android:layout_alignParentLeft:貼齊父容器左側。
  • android:layout_alignParentRight:貼齊父容器右側。
  • android:layout_below:位於指定控制項下方。
  • android:layout_above:位於指定控制項上方。
  • android:layout_toLeftOf:位於指定控制項左側。
  • android:layout_toRightOf:位於指定控制項右側。
  • android:layout_alignTop:與指定控制項頂部對齊。
  • android:layout_alignBottom:與指定控制項底部對齊。
  • android:layout_alignLeft:與指定控制項左側對齊。
  • android:layout_alignRight:與指定控制項右側對齊。

邊距與內距

  • android:layout_marginTop:距離上方邊距。
  • android:layout_marginBottom:距離下方邊距。
  • android:layout_marginLeft:距離左側邊距。
  • android:layout_marginRight:距離右側邊距。
  • android:padding:控制項內容與邊界之間的內距。

文字與圖片顯示

  • android:gravity:控制控制項內部內容的對齊方式。
  • android:layout_gravity:控制控制項在父容器中的對齊方式。
  • android:scaleType:控制 ImageView 圖片的縮放與裁切方式。
  • android:hint:輸入框為空時顯示提示文字。
  • android:singleLine:限制內容單行顯示。
  • android:ellipsize:文字過長時的省略方式。

Activity 常見設定

  • android:launchMode:Activity 啟動模式,例如 standard、singleTop、singleTask、singleInstance。
  • android:screenOrientation:螢幕方向設定。
  • android:configChanges:指定設定變更時是否自行處理。
  • android:windowSoftInputMode:控制軟鍵盤與主視窗的互動方式。

掌握這些屬性後,就能更有效率地完成 Android 介面排版與互動設計。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved