android中将tablerow用4个TextView均分

ly_yyl 2014-07-19 11:42:13
android中将tablerow用4个TextView均分怎么实现?这样为什么不对?出现不均匀的4份
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp"
android:text="@string/tv1" />
<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/tv2"
android:textSize="20sp"/>

<TextView
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="1"
android:textSize="20sp"
android:gravity="center"/>
</TableRow>
...全文
581 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
come_on_Angelababy 2015-05-28
  • 打赏
  • 举报
回复
layout_weight表示按何种比例分配剩于空间 所以把textview 的宽度设置为0dp剩余的空间就是整行 <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="0dp" android:layout_height="80dp" android:layout_weight="1" android:gravity="center" android:textSize="20sp" android:text="1111" /> <TextView android:id="@+id/tv_1" android:layout_width="0dp" android:layout_height="80dp" android:textSize="20sp" android:gravity="center" android:text="1111111111111111111" android:layout_weight="1"/> <TextView android:layout_width="0dp" android:layout_height="80dp" android:layout_weight="1" android:gravity="center" android:text="1111" android:textSize="20sp"/> <TextView android:id="@+id/tv_2" android:layout_width="0dp" android:layout_height="80dp" android:layout_weight="1" android:textSize="20sp" android:text="1" android:gravity="center"/> </TableRow>
sagittarius1988 2014-07-19
  • 打赏
  • 举报
回复
把TextView的 android:layout_width="wrap_content" 改成 android:layout_width="0dp" 看看
unloserv 2014-07-19
  • 打赏
  • 举报
回复
看看这篇文章 http://blog.sina.com.cn/s/blog_7cd0c0a80100zmfe.html
unloserv 2014-07-19
  • 打赏
  • 举报
回复
android:layout_width="wrap_content" textView的宽度=你要显示的内容的长度 你四个textView所要显示的内容的长度不一 所以textView的长度不一 所以无法均分 试试手动设置textView的宽度

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧