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

Eclipse 開發 Android 入門(10):用 LinearLayout 排出一列列茶葉

編輯:進階開發

清單裡的每一列,其實就是一段水平排列的 LinearLayout:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip">
    <TextView
        android:layout_width="wrap_content"
        ...
</LinearLayout>

關鍵在 orientation="horizontal":子元件會由左到右依序排開。搭配 layout_height="wrap_content",每一列的高度會依內容自動伸縮,不會彼此擠壓;padding 則負責把文字與邊界拉開距離。

這個模式在 Android 版面上到處可見:外層放一個垂直的 LinearLayout 當清單,內層每列再用水平的 LinearLayout 排「名稱 + 時間」兩個 TextView,就能做出整齊的列表。學會這兩層巢狀,多數清單畫面都能自己拼出來。

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