http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 2576|回复: 7

[新手开发之旅] Android新手开发之旅-基本布局方式(三)

[复制链接]
发表于 2018-11-29 16:45:42 | 显示全部楼层 |阅读模式
本节来了解帧布局(FrameLayout)和表格布局(TableLayout)

一、帧布局(FrameLayout)

     这个布局会默认把控件放在屏幕上的左上角的区域,后续添加的控件会覆盖前一个,如果控件的大小一样大的话,那么同一时刻就只能看到最上面的那个控件

     常用属性有:
        1、android:foreground:设置改帧布局容器的前景图像
          2、android:foregroundGravity:设置前景图像显示的位置

       例子:

            QQ截图20181129142326.png
实现代码:
[XML] 纯文本查看 复制代码
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@mipmap/ic_launcher"
    android:foregroundGravity="bottom">

    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@color/colorAccent" />

    <TextView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="@color/colorPrimary" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@android:color/black" />
</FrameLayout>

二、表格布局(TableLayout)
      
      Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。 当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列, 当为View时,该View将独占一行
        TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行。

      TableLayout的列数等于含有最多子控件的TableRow的列数。


       可设置的属性


       1、全局属性即列属性,有如下三个参数:

       (1)android:stretchColumns    设置可伸展的列。该列可以向行方向伸展,最多可占据一整行

       (2)android:shrinkColumns     设置可收缩的列。当该列子控件的内容太多,已经挤满所在行,那么该子控件的内容将往列方向显示

       (3)android:collapseColumns  设置要隐藏的列

       注意:以上三个参数设置值的时候索引是从“0”开始的,也可以设置多个,用逗号隔开比如”0,3”


       2、单元格属性

             (1)android:layout_column    指定该单元格在第几列显示

             (2)android:layout_span        指定该单元格占据的列数(未指定时,为1)

       示例,如下图:
               
                QQ截图20181129163617.png

       实现代码请往下看↓↓↓






1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2018-11-29 16:46:04 | 显示全部楼层
[XML] 纯文本查看 复制代码
<?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: orientation="vertical">

    <!-- android:collapseColumns="1,3" 索引从0开始,隐藏第二列和第四列 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:collapseColumns="1,3">

        <TableRow>

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

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

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

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

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

    <!-- android:stretchColumns="1" 索引从0开始,第二列可拉伸 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:stretchColumns="1">

        <TableRow>

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

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

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

    <!-- android:shrinkColumns="1" 索引从0开始,第二列可收缩 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:shrinkColumns="1">

        <TableRow>

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

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

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

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

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

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="20dp"
        android:background="@color/colorAccent" />

    <!-- android:layout_span="2" 占两列  android:layout_column="1"显示在第二列 -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp">

        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="第一列" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="第二列" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="第三列" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="第四列" />

        </TableRow>

        <!-- android:layout_span="2" 占两列 -->
        <TableRow>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_span="2"
                android:text="1" />
        </TableRow>

        <!-- android:layout_column="1"显示在第二列 -->
        <TableRow>

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

    </TableLayout>
</LinearLayout>
发表于 2018-11-29 16:50:13 | 显示全部楼层
真是难得给力的帖子啊。
发表于 2018-11-29 16:50:35 | 显示全部楼层
楼主加油,我们都看好你哦。
发表于 2018-11-29 17:27:29 | 显示全部楼层
楼主加油,我们都看好你哦。
发表于 2018-11-29 17:46:53 | 显示全部楼层
这个背景真好看
发表于 2018-11-29 18:32:03 | 显示全部楼层
看到这帖子真是高兴!
发表于 2018-12-1 10:25:54 | 显示全部楼层
楼主加油,我们都看好你哦。
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-3-29 04:27

© 2014-2021

快速回复 返回顶部 返回列表