TableLayout實現均勻佈局(條目橫向1:1排列)

像下面的佈局效果,我們經常使用LinearLayout實現,其實也可以使用TableLayout去簡單的實現

代碼如下:

                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:padding="@dimen/spacing_small"
                    android:stretchColumns="*">

                    <TableRow>

                        <TextView
                            style="@style/GrayText"
                            android:layout_width="1dp"
                            android:text="訂單號" />

                        <TextView
                            style="@style/GrayText"
                            android:layout_width="1dp"
                            android:text="預定時間" />
                    </TableRow>

                    <TableRow android:layout_marginTop="@dimen/spacing_tiny">

                        <TextView
                            android:id="@+id/order_num"
                            style="@style/BlackText"
                            android:layout_width="1dp"
                            android:text="201687" />

                        <TextView
                            android:id="@+id/time"
                            style="@style/BlackText"
                            android:layout_width="1dp"
                            android:text="2016年3月24日" />
                    </TableRow>

                    <TableRow android:layout_marginTop="@dimen/spacing_normal">

                        <TextView
                            style="@style/GrayText"
                            android:layout_width="1dp"
                            android:text="出行目的" />

                        <TextView
                            style="@style/GrayText"
                            android:layout_width="1dp"
                            android:text="訂單狀態" />
                    </TableRow>

                    <TableRow android:layout_marginTop="@dimen/spacing_tiny">

                        <TextView
                            android:id="@+id/aim"
                            style="@style/BlackText"
                            android:layout_width="1dp"
                            android:text="商務談判" />

                        <TextView
                            android:id="@+id/order_status"
                            style="@style/BlueText"
                            android:layout_width="1dp"
                            android:text="出票中" />
                    </TableRow>
                </TableLayout>

這裏有幾個屬性需要設置: android:stretchColumns=”*” TableRow裏面的子view寬度統一設置成一個固定值如1dp

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章