使用TableLayout
来源:互联网 发布:社交网络观看 编辑:程序博客网 时间:2024/04/27 23:55
最近有一个需求是显示横向显示两个TextView,左边的TextView可以多行显示。
形式如下:
情况1
AAAAAAAAAAAA bbb
情况2
AAAAAAAAAAAA bbb
AAAAAAAA
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" > <TextView android:id="@+id/right_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bbb" android:layout_alignParentRight="true" /> <TextView android:id="@+id/left_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="AAAAAAAAAAAAAAAA" android:layout_toLeftOf="@id/right_text" android:layout_marginRight="10dp" /> </RelativeLayout>最开始就是用上面的RelativeLayout的方式写的,然后发现在一些手机上(我使用的api15以下都不能正常显示情况1,即android:gravity="left" 没起作用)。
然后就考虑使用其他的布局了,最后发现TableLayout比较方便实现这个需求。代码如下:
<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkColumns="0" > <TableRow> <TextView android:id="@+id/left_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="AAAAAAAAAAAAAAAA" android:layout_marginRight="10dp" /> <TextView android:id="@+id/right_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bbb" android:layout_toLeftOf="@id/right_text" /> </TableRow></TableLayout>
关于TableLayout的使用。
TableLayout属性:
android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。
android:stretchColumns:设置指定的列为可伸展的列,以填满剩下的多余空白空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。 android:shrinkColumns:设置指定的列为可收缩的列。当可收缩的列太宽(内容过多)不会被挤出屏幕。当需要设置多列为可收缩时,将列序号用逗号隔开。
就是说可以在TableLayout中设置是否显示,是否可以伸展,是否可以收缩。我上面的例子中设置了android:shrinkColumns="0” ,即left_text是可以收缩的。
0 0
- tablelayout 使用
- 使用TableLayout
- Android学习:TableLayout使用
- TableLayout使用实例
- TableLayout的使用
- TableLayout的简单使用
- TableLayout的使用
- Android GridLayout、TableLayout使用
- Android TableLayout的使用
- TableLayout的使用
- TableLayout的使用
- TableLayout的使用
- tablelayout的使用
- tablelayout
- TableLayout
- tablelayout
- TableLayout
- TableLayout
- ORACLE 12C 导入9i导出的含有多个用户的dmp文件
- 关于数据库导出和导入sql备份文件
- C#事件与委托详解【精华 多看看】
- android设计模式
- soledede-梯度下降算法
- 使用TableLayout
- Tip_glibc的几个有用的处理二进制位的内置函数
- Type 3字体的解决办法
- About Zsh & Go2Shell & iTerm2
- java设计模式之 观察者模式
- 3-12,3-13考试总结
- 如何在 block 中修改外部变量
- override和重载的区别
- BZOJ 1509: [NOI2003]逃学的小孩