使用情景: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>

更多相关文章

  1. Android(安卓)源码获取-----在Windows环境下通过Git得到Android
  2. 鉴客 Android中如何生成带圆角的Bitmap图片
  3. 阅读手札:《:第一行代码》(第一章)
  4. 在Android(安卓)Studio中自定义字体库报错:java.lang.RuntimeExc
  5. Android_TextView属性介绍
  6. 在Ubuntu上下载、编译、运行Android内核Linux Kernel
  7. Android(安卓)studio查看sdk源代码
  8. Android(安卓)EditText实现字符过滤
  9. Android如何在service中弹出对话框

随机推荐

  1. Android(安卓)实现文件(图片)上传
  2. SystemUI9.0系统应用图标加载流程
  3. android 使用DataBinding问题总结
  4. android bugly使用
  5. Android(安卓)之开机启动Service
  6. android的文件操作
  7. android打电话和发短信
  8. Error:Execution failed for task ':app:
  9. linux下eclipse构建并编译android一个简
  10. 2013.6.18 Android(安卓)SDK和最新ADT下