TableLayout 表格布局,FrameLaout 帧布局 ,AbsoluteLayout绝对布局的分析
這三個布局就放在一起來寫了他們用的比較少,不過為了寫這遍
博客我換特意去復習了下,
第一個表格布局TableLayout
表格布局顧名思義 就是與表格類似,以行,列形式來管理其中的組件的,
它是<TableLayout> 標記定義里面必須有一個<TableRow> 作用是占用一行
語法:
<TableLayout?xmlns:android="http://schemas.android.com/apk/res/android"
? ? ? ? 屬性列表>
? <TableRow 屬性列表>
? ? ? ? ? ? ?組件?
? </TableRow>
?
</TableLayout>
幾個特有的屬性
android:collapseColumns 需要設置被隱藏的列的序列號
android:shrinkColumns ?被收縮的列的序列號
android:stretchColumns 被拉伸的列的序列號
下面寫一段代碼:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TableRowandroid:background="#ff3366" android:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#ff3366"android:text="用戶名:"/> </TableRow><TableRow android:background="#00ff00"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="密碼:"/> </TableRow></TableLayout>效果圖:
這里我設置了2中不同的背景顏色大家看到了嗎,知道我想說什么嗎
這里就提醒一下,
在TableLayout中每一個TableRow代表一行,
TableRow的寬和高
<TableRow android:background="#00ff00"android:layout_width="wrap_content"android:layout_height="wrap_content">
是固定的無論怎么設置都不會改變,不知道大家是否在意過這一點,也就是做
你不要寬和高也是一樣的,看下面的代碼我隨意改了下
再看下效果圖
怎么樣,沒有收到什么影響吧。
表格布局就說這么多吧
二 幀布局 FrameLayout
在幀布局中 每增加一個組件 將會創建一個空白的區域,
默認情況下幀布局從屏幕的左上角(0,0)坐標點開始布局,多個組件層疊排列,
后面的組件覆蓋前面的組件,
語法:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
?屬性列表>
</FrameLayout>
其特有的屬性
android:foreground 幀布局容器的前景圖像
android:foregroundGravity 前景圖像顯示的位置
資料中顯示幀布局用在游戲開發中,顯示自定義視圖,我目前開發中用到的很少
在圖片預覽的時候用到過,其他的地方沒有怎么用到過。
為了驗證:
多個組件層疊排列,
后面的組件覆蓋前面的組件, 我也寫了一個經典的demo
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="300dp"android:layout_height="300dp"android:layout_gravity="center"android:background="#cc9900"android:text="小木"/><TextViewandroid:layout_width="200dp"android:layout_height="200dp"android:layout_gravity="center"android:background="#00ff00"android:text="小木"/><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="center"android:background="#ff00cc"android:text="小木"/><TextViewandroid:layout_width="50dp"android:layout_height="50dp"android:layout_gravity="center"android:background="#ffffff"android:text="小木"/> </FrameLayout>
效果圖:
三 ?AbsoluteLayout絕對布局
現在幾乎不用了,用了它之后無法再進行適配了,原因嗎?看下他的特點吧
特點:坐標的方式來定位在屏幕上的位置,引起缺乏靈活性,在沒有絕對定位的情況下相比其他類型的布局更難維護
把剛才的代碼拿來看看吧
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="300dp"android:layout_height="300dp"android:layout_gravity="center"android:background="#cc9900"android:text="小木"/><TextViewandroid:layout_width="200dp"android:layout_height="200dp"android:layout_gravity="center"android:background="#00ff00"android:text="小木"/><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="center"android:background="#ff00cc"android:text="小木"/><TextViewandroid:layout_width="50dp"android:layout_height="50dp"android:layout_gravity="center"android:background="#ffffff"android:text="小木"/> </AbsoluteLayout>
這個就說這么多吧,我查了下資料說在android2.0之后就標記過期了,
自己也是只有有這么一個布局,不過從來沒有用到實際的項目中。
總結
以上是生活随笔為你收集整理的TableLayout 表格布局,FrameLaout 帧布局 ,AbsoluteLayout绝对布局的分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RelativeLayout(相对布局)
- 下一篇: error: No resource i