Android问题集(七)——TableLayout 中让TableRow中的控件填充满整列
16lz
2021-01-24
使用情景:TableLayout、TableRow及其内的button控件width都设为android:layout_width="match_parent"
,但button不填充满宽度,实际显示如下:
代码如下:
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:layout_width="match_parent" android:layout_height="match_parent" /> TableRow>TableLayout>
原因:在表格布局中,列默认不可拉伸,即使设置android:layout_width="match_parent"
,显示效果为上图。若要使列控件填充整行,则在TableLayout
属性中配置android:stretchColumns=""
。
android:stretchColumns属性:
功能:设置允许被拉伸的列的序列号(序列号从0开始),多个序列号中间用“,”分隔。
如上的代码只需在TableLayout中增加属性android:stretchColumns="0"
即可,效果如下:
更改后代码如下:
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="0"> <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <Button android:layout_width="match_parent" android:layout_height="match_parent" /> TableRow>TableLayout>
更多相关文章
- Android(安卓)源码获取-----在Windows环境下通过Git得到Android
- 鉴客 Android中如何生成带圆角的Bitmap图片
- 阅读手札:《:第一行代码》(第一章)
- 在Android(安卓)Studio中自定义字体库报错:java.lang.RuntimeExc
- Android_TextView属性介绍
- 在Ubuntu上下载、编译、运行Android内核Linux Kernel
- Android(安卓)studio查看sdk源代码
- Android(安卓)EditText实现字符过滤
- Android如何在service中弹出对话框