天天看點

TableLayout不能占滿螢幕問題解決

TableLayout不能占滿螢幕問題解決

TableLayout不能設定寬度導緻目前界面并沒有充分利用螢幕的寬度,右側還空出了一塊區 域 ,

這 也 難 怪 , 因 為 在 TableRow 中 我 們 無 法 指 定 控 件 的 寬 度 。 這 時 使 用

android:stretchColumns 屬性就可以很好地解決這個問題,它允許将 TableLayout 中的某一列

進行拉伸,以達到自動适應螢幕寬度的作用。修改 activity_main.xml 中的代碼,如下所示:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
>
……
</TableLayout>
           

這裡将 android:stretchColumns 的值指定為 1,表示如果表格不能完全占滿螢幕寬度,就

将第二列進行拉伸。沒錯!指定成 1 就是拉伸第二列,指定成 0 就是拉伸第一列,不要以為

這裡我寫錯了哦。重新運作程式

TableLayout不能占滿螢幕問題解決

繼續閱讀