TableLayout 表格布局

tablelayout简介

表格布局有TableLayout代表,但是它的本质定义仍然是线性管理器。表格布局采用行和列来管理UI,但是不需要明确的定义多少行,多少列,而是通过添加TableRow,没添加一个TableRow,就添加一行,TableRow中每添加一个组件就是一列。

TableLayout属性

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical">
   <TableLayout
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:shrinkColumns="1"
        android:stretchColumns="2">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello "/>
       <TableRow>
           <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="hello "/>
           <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="hello "/>
           <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="hello "/>

       </TableRow>

       </TableLayout>
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:collapseColumns="1">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello "/>
        <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>

        </TableRow>

    </TableLayout>
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1,2">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello "/>
        <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>

        </TableRow>
        <TableRow>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="hello "/>
        </TableRow>

    </TableLayout>
</LinearLayout>

FrameLayout帧布局

帧布局是由FrameLayout所代表,FrameLayout直接继承了ViewGroup属性。帧布局为每一个加入的控件创建一个空白的区域,称为一帧,每个子组件占据一帧,这些帧都会根据gravity属性,自动对齐。

FrameLayout的属性



子组件会受到FrameLayout.layoutParam的控制,可指定

android:layout_gravity来控制对齐方式。

Frame霓虹灯实例

package peng.liu.testview;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends Activity {
    private int[] names = new int[]{
            R.id.view01,
            R.id.view02,
            R.id.view03,
            R.id.view04,
            R.id.view05,
            R.id.view06
    };
    private int[] colors = new int[]{
            R.color.color1,
            R.color.color2,
            R.color.color3,
            R.color.color4,
            R.color.color5,
            R.color.color6
    };
    private int currentColor = 0;
    TextView[] texts = new TextView[names.length];
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0x123){
                for(int i =0;i<names.length;i++){
                    texts[i].setBackgroundResource(colors[(i + currentColor) % names.length]);
                }
                currentColor++;
            }
            super.handleMessage(msg);
        }
    } ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        for(int i=0;i<names.length;i++){
            texts[i] = (TextView) findViewById(names[i]);
        }
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(0x123)
            }
        },0,200);
    }
}

布局代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical">
   <FrameLayout
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
        <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/view01"
       android:layout_gravity="center"
       android:background="@color/color1"
       android:width="320px"
       android:height="320px"
       />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/view02"
           android:layout_gravity="center"
           android:background="@color/color2"
           android:width="280px"
           android:height="280px"
           />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/view03"
           android:layout_gravity="center"
           android:background="@color/color3"
           android:width="240px"
           android:height="240px"
           />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/view04"
           android:layout_gravity="center"
           android:background="@color/color4"
           android:width="200px"
           android:height="200px"
           />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/view05"
           android:layout_gravity="center"
           android:background="@color/color5"
           android:width="160px"
           android:height="160px"
           />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/view06"
           android:layout_gravity="center"
           android:background="@color/color6"
           android:width="120px"
           android:height="120px"
           />
       </FrameLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="color1">#f00</color>
    <color name="color2">#0f0</color>
    <color name="color3">#00f</color>
    <color name="color4">#ff0</color>
    <color name="color5">#f0f</color>
    <color name="color6">#0ff</color>
</resources>

android布局##TableLayout和FrameLayout-android学习之旅(十五)的更多相关文章

  1. Spring学习之旅(十五)--SpringBoot

    在使用 Spring 的过程中,有时候会出现一些 ClassNotFoundException 异常,这是因为 JAR 依赖之间的版本不匹配所导致的.而 Spring Boot 就能避免绝大多数依赖版 ...

  2. 我的MYSQL学习心得(十五) 日志

    我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  3. 别人的的MYSQL学习心得(十五) 日志

    我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  4. VSTO学习笔记(十五)Office 2013 初体验

    原文:VSTO学习笔记(十五)Office 2013 初体验 Office 2013 近期发布了首个面向消费者的预览版本,我也于第一时间进行了更新试用.从此开始VSTO系列全面转向Office 201 ...

  5. Nodejs学习笔记(十五)--- Node.js + Koa2 构建网站简单示例

    目录 前言 搭建项目及其它准备工作 创建数据库 创建Koa2项目 安装项目其它需要包 清除冗余文件并重新规划项目目录 配置文件 规划示例路由,并新建相关文件 实现数据访问和业务逻辑相关方法 编写mys ...

  6. [转]Nodejs学习笔记(十五)--- Node.js + Koa2 构建网站简单示例

    本文转自:https://www.cnblogs.com/zhongweiv/p/nodejs_koa2_webapp.html 目录 前言 搭建项目及其它准备工作 创建数据库 创建Koa2项目 安装 ...

  7. python3.4学习笔记(二十五) Python 调用mysql redis实例代码

    python3.4学习笔记(二十五) Python 调用mysql redis实例代码 #coding: utf-8 __author__ = 'zdz8207' #python2.7 import ...

  8. Nodejs学习笔记(十五)—Node.js + Koa2 构建网站简单示例

    前言 前面一有写到一篇Node.js+Express构建网站简单示例:http://www.cnblogs.com/zhongweiv/p/nodejs_express_webapp.html 这篇还 ...

  9. 学习笔记:CentOS7学习之二十五:shell中色彩处理和awk使用技巧

    目录 学习笔记:CentOS7学习之二十五:shell中色彩处理和awk使用技巧 25.1 Shell中的色彩处理 25.2 awk基本应用 25.2.1 概念 25.2.2实例演示 25.3 awk ...

  10. 风炫安全web安全学习第三十五节课 文件下载和文件读取漏洞

    风炫安全web安全学习第三十五节课 文件下载和文件读取漏洞 0x03 任意文件下载漏洞 一些网站由于业务需求,往往需要提供文件下载功能,但若对用户下载的文件不做限制,则恶意用户就能够下载任意敏感文件, ...

随机推荐

  1. [Educational Codeforces Round#22]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 晚上去clj博客逛来逛去很开心,突然同学提醒了一下,发现cf已经开始40分钟了,慌的一B,从B题开始写,写完了B到E最后收掉了A,结果太着急B ...

  2. SpringCloud学习之feign

    一.关于feigin feigin是一种模板化,声明式的http客户端,feign可以通过注解绑定到接口上来简化Http请求访问.当然我们也可以在创建Feign对象时定制自定义解码器(xml或者jso ...

  3. 如何让Mac、Windows可以互相远程

    您可以通过Mac来远程Windows桌面:也可通过Windows来远程Mac界面:甚至还可以通过iOS或Android来远程Mac或Windows. Windows的操作方法,以Windows XP ...

  4. C语言作业程序设计第一次作业

    1.求圆面积和面积 (1)题目: 输入圆的半径,计算圆的周长和面积 (2)流程图: (3)测试数据及运行结果 测试数据:r=4 运行结果: (4)实验分析 没有遇到问题 2.判断闰年问题 (1)题目: ...

  5. Android开发Java基础之Java语言基础(1)

    Java中的基本数据类型 整数类型 整数类型用来存储整数数值,既没有小数部分的数值.可以是正数,也可以是负数.整数类型在Java程序中有三种表现形式,分别是十进制,八进制,十六进制. 整型数据根据它所 ...

  6. Linux常用命令大全(归类)

    最近都在和Linux打交道,这方面基础比较薄弱的我只好买了本鸟哥的书看看,感觉还不错.我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因, ...

  7. Mysql锁机制--索引失效导致行锁变表锁

    Mysql 系列文章主页 =============== Tips:在阅读本文前,最好先阅读 这篇(Mysql锁机制--行锁)文章~ 在上篇文章中,我们看到InnoDB默认的行锁可以使得操作不同行时不 ...

  8. java对redis的操作

    需要两个包的支持 jedis-2.1.0.jar commons-pool-1.5.4.jar 一个连接池一个工具类 pool代码 public class RedisUtil { private s ...

  9. application-config.xml和mvc-config.xml的区别

    头一个放bean之类的东西 后一个放controllers, view resolvers之类的东西

  10. 吴恩达深度学习第1课第3周编程作业记录(2分类1隐层nn)

    2分类1隐层nn, 作业默认设置: 1个输出单元, sigmoid激活函数. (因为二分类); 4个隐层单元, tanh激活函数. (除作为输出单元且为二分类任务外, 几乎不选用 sigmoid 做激 ...