zoukankan      html  css  js  c++  java
  • 表格布局TableLayout

    简单实现计算机界面布局的案例:

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="*">      //android:stretchColumns="*"填满多余空间的属性

    <TextView
    android:gravity="right|center"   //textView1的文字居右然后居中
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="50dp"  //设置高度
    android:text="90" />

    <TableRow    //表格行
    android:layout_weight="1"  //设置权重之后就能平均分配整个屏幕 ,如果不设置就有空白处
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"  //高度要设为match_parent 不然按钮就不会占满行
    android:text="7" /> 

    <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="8" />

    <Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="9" />

    <Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="/" />

    </TableRow>

    <TableRow
    android:layout_weight="1"
    android:id="@+id/tableRow2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="4" />

    <Button
    android:id="@+id/button6"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="5" />

    <Button
    android:id="@+id/button7"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="6" />

    <Button
    android:id="@+id/button8"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="*" />

    </TableRow>

    <TableRow
    android:layout_weight="1"
    android:id="@+id/tableRow3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
    android:id="@+id/button9"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="1" />

    <Button
    android:id="@+id/button10"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="2" />

    <Button
    android:id="@+id/button11"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="3" />

    <Button
    android:id="@+id/button12"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="-" />

    </TableRow>

    <TableRow
    android:layout_weight="1"
    android:id="@+id/tableRow4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
    android:id="@+id/button13"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="0" />

    <Button
    android:id="@+id/button14"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="." />

    <Button
    android:id="@+id/button15"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="+" />

    <Button
    android:id="@+id/button16"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="=" />

    </TableRow>

    <TableRow
    android:layout_weight="1"
    android:id="@+id/tableRow5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

    <Button
    android:layout_span="4"  //最后一行只有一个按钮,设置android:layout_span就说明占4个位置(全部沾满)
    android:id="@+id/button17"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:text="clear" />

    </TableRow>

    </TableLayout>

    完成之后

  • 相关阅读:
    mysql truncate
    蠕虫复制
    mysql 一对多,多对多
    php实现文件下载
    JetBrains PhpStorm 整个项目中查找一个词语
    vim
    程序员减少代码BUG的7种方法,拒绝编程5分钟,查代码2小时!
    创建你的第一个Composer/Packagist包
    Elasticsearch
    Laravel 实践之路: 数据库迁移与数据填充
  • 原文地址:https://www.cnblogs.com/chaowang/p/6095031.html
Copyright © 2011-2022 走看看