Android开发菜单布局之表格布局示例

 更新时间:2019年04月17日 14:08:08   作者:水中鱼之1999  
这篇文章主要介绍了Android开发菜单布局之表格布局,结合具体实例形式分析了Android菜单布局中表格布局的相关行列排版与设置操作技巧,需要的朋友可以参考下

本文实例讲述了Android开发菜单布局之表格布局。分享给大家供大家参考,具体如下:

多用于静态菜单页面

xml代码

代码内带详细解释

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/root"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <!--分别以0,1,2 对应 1,2,3列-->
  <!--定义第 1 个表格布局,第二列收缩第三列拉伸-->
  <TableLayout
    android:id="@+id/TableLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="1"
    android:stretchColumns="2">
    <!--第一行不使用TableRow自己会占一行-->
    <Button
      android:id="@+id/ok1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="第一行不使用TableRow自己会占一行"/>
    <!--添加一个表格-->
    <TableRow>
      <Button
        android:id="@+id/ok2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="无设置 按钮"/>
      <Button
        android:id="@+id/ok3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="收缩的 按钮"/>
      <Button
        android:id="@+id/ok4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="拉伸的 按钮"/>
    </TableRow>
  </TableLayout>
  <!--定义第 2 个表格布局,第二列隐藏-->
  <TableLayout
    android:id="@+id/TableLayout02"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:collapseColumns="1">
    <!--第一行不使用TableRow自己会占一行-->
    <Button
      android:id="@+id/ok5"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="第一行不使用TableRow自己会占一行"/>
    <!--添加一个表格-->
    <!--由于设置collapseColumns="1"故第二列隐藏-->
    <TableRow>
      <Button
        android:id="@+id/ok6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮1"/>
      <Button
        android:id="@+id/ok7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮2"/>
      <Button
        android:id="@+id/ok8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮3"/>
    </TableRow>
  </TableLayout>
  <!--定义第 3 个表格布局,第二列和第三列拉伸-->
  <!--多行花式设计-->
  <TableLayout
    android:id="@+id/TableLayout03"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1,2">
    <!--第一行不使用TableRow自己会占一行-->
    <Button
      android:id="@+id/ok9"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="第一行不使用TableRow自己会占一行"/>
    <!--添加一个表格-->
    <!--由于设置collapseColumns="1"故第二列隐藏-->
    <TableRow>
      <Button
        android:id="@+id/ok10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="无设置 按钮"/>
      <Button
        android:id="@+id/ok11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="拉伸的 按钮"/>
      <Button
        android:id="@+id/ok14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="拉伸的 按钮"/>
    </TableRow>
    <!--第二行单列-->
    <TableRow>
    <Button
      android:id="@+id/ok15"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="无设置 按钮"/>
      <Button
        android:id="@+id/ok16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="拉伸的 按钮"/>
  </TableRow>
    <TableRow>
    <Button
      android:id="@+id/ok17"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="无设置 按钮"/>
  </TableRow>
  </TableLayout>
</LinearLayout>

效果图:

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android布局layout技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》及《Android控件用法总结

希望本文所述对大家Android程序设计有所帮助。

相关文章

  • Android异常处理最佳实践

    Android异常处理最佳实践

    这篇文章主要为大家详细介绍了Android异常处理最佳实践,介绍了一个优秀的app异常处理机制包括什么,感兴趣的小伙伴们可以参考一下
    2016-03-03
  • Android利用Espresso进行UI自动化测试的方法详解

    Android利用Espresso进行UI自动化测试的方法详解

    因为我是搞android开发的,所以被分到了自动化测试小组,所以了解了一些UI自动化测试。下面这篇文章主要给大家介绍了关于Android利用Espresso进行UI自动化测试的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧。
    2017-12-12
  • Android NoSuchFieldError解决办法

    Android NoSuchFieldError解决办法

    这篇文章主要介绍了Android NoSuchFieldError解决办法的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
    2017-10-10
  • Android仿微信多人音视频通话界面

    Android仿微信多人音视频通话界面

    这篇文章主要为大家详细介绍了Android仿微信多人音视频通话界面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-07-07
  • Android Https证书过期的两种解决方案

    Android Https证书过期的两种解决方案

    应该有很多小伙伴遇到这样一个问题,在线上已发布的app里,关于https的cer证书过期,从而导致app所有网络请求失效无法使用,这篇文章主要介绍了Android Https证书过期的解决方案,需要的朋友可以参考下
    2022-12-12
  • Flutter中数据存储的四种方式小结

    Flutter中数据存储的四种方式小结

    在 Flutter 中,存储是指用于本地和远程存储和管理数据的机制,本给大家介绍了Flutter中不同存储选项的概述和示例,通过代码示例讲解的非常详细,具有一定的参考价值,需要的朋友可以参考下
    2023-11-11
  • android上实现0.5px线条的原理分析

    android上实现0.5px线条的原理分析

    这篇文章主要介绍了android上实现0.5px线条的原理分析,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-01-01
  • Android 处理 View 重复点击的多种方法

    Android 处理 View 重复点击的多种方法

    这篇文章主要介绍了Android 处理 View 重复点击的多种方法,帮助大家更好的理解和学习使用Android,感兴趣的朋友可以了解下
    2021-03-03
  • 详解Android观察者模式的使用与优劣

    详解Android观察者模式的使用与优劣

    这篇文章主要介绍了Android观察者模式的相关资料,帮助大家更好的理解和学习Android的设计模式,感兴趣的朋友可以了解下
    2020-09-09
  • APK包名修改 请问如何修改APK包名

    APK包名修改 请问如何修改APK包名

    今天,想在android手机上安装两个相同的应用,本以为可以安装不同版本的,试了几次,均相互覆盖了,于是,只能设法修改apk所对应的包名(package name),需要了解的朋友可以参考下
    2012-12-12

最新评论