• Activity 布局初步


    这里我们看两个布局方式,LinearLayout TableLayout 线性布局和表格布局

    由于java代码很简单,只是制定了布局文件,所以就不写上来了

    我们先看下线性布局

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="fill_parent"
     4     android:layout_height="fill_parent"
     5     android:orientation="vertical" >
     6 <!-- android:layout_weight 这是一个比例 -->
     7     <TextView
     8         android:id="@+id/firstText"
     9         android:layout_weight="1"
    10         android:background="#aa0000"
    11         android:gravity="center_vertical"
    12         android:layout_height="wrap_content"
    13         android:paddingBottom="40dip"
    14         android:paddingLeft="10dip"
    15         android:paddingRight="30dip"
    16         android:paddingTop="20dip"
    17         android:singleLine="true"
    18         android:text="第一行"
    19         android:textSize="35pt"
    20         android:layout_width="fill_parent" />
    21 
    22     <TextView
    23         android:id="@+id/secondText"
    24         android:layout_weight="1"
    25         android:background="#0000aa"
    26         android:gravity="center_vertical"
    27         android:layout_height="wrap_content"
    28         android:text="第二行"
    29         android:textSize="18pt"
    30         android:layout_width="fill_parent" />
    31 
    32     <Button
    33         android:id="@+id/calculate"
    34         android:layout_width="fill_parent"
    35         android:layout_height="wrap_content" />
    36 
    37 </LinearLayout>

    再看一下表格布局

     1 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="fill_parent"
     4     android:layout_height="fill_parent"
     5     android:stretchColumns="1" >
     6 
     7     <!-- android:stretchColumns 制定可拉伸的列为哪一个列 -->
     8 
     9     <TableRow>
    10 
    11         <TextView
    12             android:padding="3dip"
    13             android:text="1" />
    14 
    15         <TextView
    16             android:gravity="center_horizontal"
    17             android:padding="3dip"
    18             android:text="5" />
    19 
    20         <TextView
    21             android:gravity="right"
    22             android:padding="3dip"
    23             android:text="2" />
    24     </TableRow>
    25 
    26     <TableRow>
    27 
    28         <TextView
    29             android:padding="3dip"
    30             android:text="3" />
    31 
    32         <TextView
    33             android:gravity="center_horizontal"
    34             android:padding="3dip"
    35             android:text="6" />
    36 
    37         <TextView
    38             android:gravity="right"
    39             android:padding="3dip"
    40             android:text="4" />
    41     </TableRow>
    42 
    43 </TableLayout>
  • 相关阅读:
    (转)IDEA ERROR:找不到或无法加载主类
    Piggy-Bank
    Monkey and Banana
    Max Sum Plus Plus
    Doing Homework
    繁繁的游戏
    看试卷
    繁繁的队列
    大整数乘法
    文件操作(c++)
  • 原文地址:https://www.cnblogs.com/zhuzhenyu/p/2613013.html
Copyright © 2020-2023  润新知