歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android布局方式之表格布局管理器(TableLayout)

Android布局方式之表格布局管理器(TableLayout)

日期:2017/3/1 10:48:43   编辑:Linux編程

在Android中,線性布局和表格布局用的是最多的。

在很多的輸出操作中,往往會使用表格的形式對顯示的數據進行排版,tablelayout采用表格形式對控件的布局進行管理的,在布局的管理中,要使用TableRow進行表格行的控制,之後所有的組件要在tableRow中進行增加:

如圖:

下面我們就看看一個典型的tableLayout的布局方式:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <TableRow >
  8. <EditText
  9. android:id="@+id/input"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:hint="請輸入查找字符"
  13. />
  14. <Button
  15. android:id="@+id/search"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:text="查找"
  19. />
  20. </TableRow >
  21. <View
  22. android:layout_height="2px"
  23. android:layout_width="fill_parent"
  24. android:background="#FF909032"
  25. />
  26. <TableRow >
  27. <TextView
  28. android:id="@+id/views"
  29. android:layout_width="wrap_content"
  30. android:layout_height="wrap_content"
  31. android:text="請選擇編碼"
  32. />
  33. <RadioGroup >
  34. <RadioButton
  35. android:id="@+id/radiobtn1"
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content"
  38. android:text="UTF_8"
  39. />
  40. <RadioButton
  41. android:id="@+id/radiobtn2"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:text="SHIF_JIS"
  45. />
  46. </RadioGroup>
  47. </TableRow>
  48. </TableLayout>
主要實現是通過TableLayout裡面嵌套不同的widget來做到的。結果運行如下:


其中的一個分隔符是view來達到這種分割的現實效果的。

Copyright © Linux教程網 All Rights Reserved