TableLayout实现均匀布局(条目横向1:1排列)

来源:互联网 发布:win7 激活软件 编辑:程序博客网 时间:2024/06/07 00:59

像下面的布局效果,我们经常使用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

0 0
原创粉丝点击