android学习——使用TableLayout动态生成表格,并为tablerow中的列添加点击监听

      在android中实现表格的形式主要有三种:一是Gridview ,实现网状布局,但是它的行和列的大小是定的;二是ListView,这在实际应用中应该用的最多的,它可以通过Layout_weight 属性,实现不同的尺寸列显示,但是当设定Layout_weight 值后,列的尺寸也是固定了的。三是TableLayout,这是文档中专门用于表格显示的布局,通过 android:shrinkColumns (自动缩进列长度) 和  android:stretchColumns (自动延伸列长度) 属性可以实现列尺寸的自动缩进和延伸。

     下面的例子也是结合了很多参考内容写出来的,在这只想和大家分享,希望能帮到有需要的人。

     首先,说说背景吧,最近在做毕设,这个例子也就是其中的一个模块——课程查询。该模块提供两种功能,一个是按学院名查询课程,另一个是按课程名查询课程。并将查询的结构显示在TableLayout布局中,TableLayout的使用可以找些博文,有些讲的非常清楚,在这我就不累赘。先贴一段布局文件的代码,没什么好解释的,都是些简单的布局,所以比较难看。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chat_background"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/kechengchaxun_anxueyuanchaxun"
            android:textSize="18sp" />

        <Spinner
            android:id="@+id/kccx_spinner1"
            android:layout_width="200dip"
            android:layout_height="50dp" />

        <Button
            android:id="@+id/kccx_chaxun1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/kechengchaxun_chaxun" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="10.0dip"
        android:background="@drawable/fengeview" >
    </View>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/kechengchaxun_ankechengchaxun"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/kccx_course_name"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:inputType="textCapWords" />

        <Button
            android:id="@+id/kccx_chaxun2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/kechengchaxun_chaxun" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="20.0dip"
        android:background="@drawable/fengeview" >
    </View>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

        <TableLayout
            
            android:l
  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值