iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android入门之TableLayout应用解析(二)
  • 110
分享到

Android入门之TableLayout应用解析(二)

Android 2022-06-06 10:06:40 110人浏览 八月长安
摘要

本文在上一篇初步介绍TableLayout常用属性的基础上,将进一步介绍如何UI设计器设计TableLayout + TableRow。由于实际应用中,经常需要在代码里往Tab

本文在上一篇初步介绍TableLayout常用属性的基础上,将进一步介绍如何UI设计器设计TableLayout + TableRow。由于实际应用中,经常需要在代码里往TableLayout添加数据(9宫图也可以用TableLayout做出来 ),本文就是介绍这方面的简单使用方法。

main.xml的代码如下,用到TableLayout的ID为TableLayout01:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="Http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
   <TableLayout 
       android:id="@+id/TableLayout01" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content">
   </TableLayout>
</LinearLayout>

JAVA代码部分如下:


package com.LayoutDemo;
import com.LayoutDemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class LayoutDemo extends Activity {
  
 private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
 private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //新建TableLayout01的实例
    TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01);
    //全部列自动填充空白处
    tableLayout.setStretchAllColumns(true);
    //生成10行,8列的表格
    for(int row=0;row<10;row++)
    {
      TableRow tableRow=new TableRow(this);
      for(int col=0;col<8;col++)
      {
       //tv用于显示
       TextView tv=new TextView(this);
        tv.setText("("+col+","+row+")");
        tableRow.addView(tv);
      }
      //新建的TableRow添加到TableLayout
      tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC));
    }
  }
}

结果如下图:

您可能感兴趣的文章:Android TabLayout(选项卡布局)简单用法实例分析Extjs扩展 垂直tabLayout实现代码Jquery EasyUI 中文api Layout(Tabs)Android开发笔记 TableLayout常用的属性介绍Android入门之TableLayout应用解析(一)Android TableLayout数据列表的回显清空实现思路及代码Android布局(RelativeLayout、TableLayout等)使用方法Android布局之TableLayout表格布局Android开发之TableLayout表格布局android TabLayout使用方法详解


--结束END--

本文标题: Android入门之TableLayout应用解析(二)

本文链接: https://www.lsjlt.com/news/27002.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作