如何在Android中设置表列

设置表行的布局参数(包含文本视图)有一些困难.

我想添加一些列以获得良好的布局.我在做动态(代码)

<TableRow> 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ok"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bye"/>
</TableRow>

我希望这两个文本视图成为两列,并相应地在屏幕上布局.

解决方法

你已经写过的东西实际上已经可以创建了两列,事实上它们可能不像您期望的那样在屏幕上放置 – 列将尽可能的窄. Android布局中的TableLayout标记有几个属性.其中一个是拉伸柱 – 如果给定描述的柱将被拉伸,以便填充所有指定的宽度.如果您需要所有这些均匀地使用星标,如果希望使用其基于1的索引来延伸覆盖剩余空间的任何特定列(您可以指定一组索引).看这里:
<TableLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:stretchColumns="0,1" >
   <TableRow android:layout_width="fill_parent"> 
     <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="ok"    
      />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="bye" />
   </TableRow>
</TableLayout>

顺便说一句,如果你只需要一行,你可以对LinearLayout和orientation =“horizo​​ntal”做同样的事情.如果您有几行,请记住,您真正处理表 – 列的所有行将完全位于另一列之上,最宽的行将确定列的宽度.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...