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

本文介绍了如何利用TableLayout在Android中实现条目横向1:1排列的布局效果,通过设置`android:stretchColumns=”*”`和TableRow子view宽度,达到类似LinearLayout的布局目的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值