Android中TableLayout中的布局
1.在TableLayout下的代碼及效果
<TableRow> <TextView android:text="tmacsky" /> <TextView android:text="tmacsky" /> <TextView android:text="tmacsky" /> </TableRow> <TableRow> <Button android:text="tmacsky" /> <Button android:text="tmacsky" /> <Button android:text="tmacsky" android:layout_weight="1" /> </TableRow> <TableRow> <EditText /> <EditText /> <EditText android:layout_weight="1"/> </TableRow>

單個列布局中只能用layout_weight來拉寬,如果布局很多就有點繁瑣了,所以得用到下面的stretchColumns伸縮列
2. Android:stretchColumns 伸縮列
代碼和效果:
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0,1,2" > //(此處表示第1,2,3列都拉寬屏幕) <TableRow> <TextView android:text="tmacsky1" /> <TextView android:text="tmacsky2" /> <TextView android:text="tmacsky3" /> </TableRow> <TableRow> <Button android:text="tmacsky1" /> <Button android:text="tmacsky2" /> <Button android:text="tmacsky3" /> </TableRow> <TableRow> <EditText /> <EditText /> <EditText /> </TableRow> </TableLayout>

由此可以想象伸縮列其實就是用weight來封裝的
3. android:collapseColumns縮進列
將第2個例子里的Android:stretchColumns縮進下加一行代碼:
android:collapseColumns="0"
意思就是縮進第一列效果:

4,如果按鈕里文字過多,則會出現下面這種情況
超出屏幕了;這個時候如果想讓按鈕里的文字換行不超出屏幕則可以:
在第二個例子的Android:stretchColumns添加一行代碼:
android:shrinkColumns="2"

5.實現下面的效果
在第二個例子里的EditText代碼改成這樣:
<TableRow>
<EditText android:layout_span="2"/>
<EditText android:layout_column="2"/>
</TableRow>
Layout_span=”2” 伸展2倍
Layout_column=”2” 位置固定到第三列
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!