• Android布局


    布局可以套用布局
    <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:orientation= "vertical"
         >
        <LinearLayout ></LinearLayout >
    </LinearLayout  >
     
    常用布局  LinearLayout,RelativeLayout
     
     
    LinearLayout  线性布局
         包含的子控件将以横向或竖向的方式排列。
    LinearLayout属性:
         android:orientation="vertical"     该属性决定他子类控件的排布方式(vertical(垂直)/horizontal(水平))
         android:gravity="center"     该属性决定他子类的xy的位置。
    常用到的几个属性值:
         1.center_vertical:垂直居中
         2.center_horizontal:水平居中
         3.center:水平垂直都居中
         4.right:子类控件位于当前布局的右边
         5.left:子类控件位于当前布局的左边
         6.bottoom:子类控件位于当前布局的下面
     
    <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:orientation= "vertical"
        android:gravity= "bottom|center_horizontal"          //可以多个属性连用     
         >
     
        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:text= "Button" />
     
    </LinearLayout  >
     
    子类控件在LinearLayout中常用到的属性
    layout_gravity调整该布局相对父布局的位置
    gravity是调整该布局中子布局的位置
    android:layout_gravity="bottom"     指本身在当前父容器的XY的位置
    android:layout_weight="1"     指本身空间占当前父容器的一个比例
     <Button
            android:layout_weight="2"     //将页面分为三份
            android:layout_gravity="center_horizontal"
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />
       
        <Button
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button" />
     
     
     
    RelativeLayout 相对布局
     
    RelativeLayout是相对布局控件,它包含的子控件将以控件之间的相对位置或者子类控件相对于父类容器的位置的方式排列
    子类控件在RelativeLayout中常用到的属性(相对父容器的一个位置)
    android:layout_alignParentLeft="true"     子类控件相对当前父类容器靠左边
    android:layout_alignParentTop="true"     子类控件相对父类容器靠上边
    android:layout_marginLeft="41dp"     子类控件距离父类容器左边的距离
    android:layout_marginTop="33dp"     子类控件距离父类容器上边的距离
    android:layout_centerInparrent="true"     子类控件相对父类容器即水平居中又垂直居中
    android:layout_centerHorizontal="true"     子类控件相对于父类容器水平居中
    android:layout_centerVertical="true"     子类控件相对于父类容器垂直居中
     
     
    <RelativeLayout   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"
         >
             <Button
                   android:id="@+id/bt1"
                   android:text="1"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
            />
     
    </RelativeLayout  >
     
     
     
    android:layout_below="@+id/button"     该控件位于给定ID控件的底部
    android:layout_toRightOf="@+id/button"     该控件位于给定ID控件的右边
    android:layout_above="@+id/button"     该控件位于给定ID控件的上面
    android:layout_toLeftOf="@+id/button"     该控位于给定ID控件的左边
    android:layout_alignBaseline="@+id/button"     该控件的内容与给定ID控件的内容在一条直线上
    android:layout_alignBottom     该控件的底部边缘与给定ID控件的底部边缘对齐
    android:layout_alignLeft     该控件的左边缘与给定ID控件的左边缘对齐
    android:layout_alignRigth     该控件的右边缘与给定ID控件的右边缘对齐
    android:layout_alignTop     该控件的顶部边缘与给定ID控件的顶部对齐
     
     
     <Button
                   android:id="@+id/bt1"
                   android:text="1"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
            />
            
             <!-- android:layout_alignBaseline="@+id/bt1"  文字在与绑定ID BT1的同一水平线上 -->
            
             <Button
                android:layout_alignBaseline="@+id/bt1"    
                android:layout_toRightOf="@+id/bt1"
                   android:id="@+id/bt2"
                   android:text="2"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                 />
     
    帧布局 FrameLayout
         所有的子元素都不能被指定放置的位置,他们统统放于这块区域的左上角,并且后面的子元素直接覆盖前面的子元素之上,将前面的子元素部分和全部遮挡。
    <FrameLayout   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:foreground ="@drawable/on"      // 设置前景图
        >
        <TextView
            android:layout_gravity="center"
            android:id="@+id/textView1"
            android:layout_width="200dp"
            android:layout_height="200dp"
             android:background= "#785435"
            android:text="1111111111111111111" />
     
        <TextView
            android:layout_gravity="center"
            android:id="@+id/textView2"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#564238"
            android:text="2222222222222222222" />
     
    </FrameLayout  >
    ————————————————————————————————————————————————————————————————————————————————————————
    <ProgressBar
            android:layout_gravity="center"
            android:id="@+id/progressBar1"
            style= "?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
     
        <TextView
            android:layout_gravity="center"
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20%" />
     
     
     
    绝对布局 AbsoluteLayout(使用决定定位适应性会比较差,屏幕适配会有缺陷)
         又叫坐标布局,可以直接指定子元素的绝对位置即子元素X、Y的坐标。
         android:layout_x:"35dip"
         android:layout_y:"35dip"
    <AbsoluteLayout   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:foreground= "@drawable/on"
        >
     
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_x="45dp"
            android:layout_y="32dp"     //绝对位置
            android:text="Button" />
     
    </AbsoluteLayout>
     
     
    表格布局  TableLayout
    TableLayout表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。
    android:collapseColumns="1,2"     隐藏从0开始的索引列,列直接必须用逗号隔开
    android:shrinkColumns="1,2"     收缩从0开始的索引列。当可收缩的列太宽不会被挤出屏幕,列直接必须用逗号隔开,可以通过“*”代替收缩所有列.注意一列能同时表示收缩和拉伸。
    android:stretchColumns="1,2"     拉伸从0开始的索引列。以填满剩下的多余空白空间。列直接必须用逗号隔开,可以通过“*”代替收缩所有列.注意一列能同时表示收缩。
    <?xml version= "1.0" encoding ="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:collapseColumns= "1,2"
        android:shrinkColumns= "1,2"
        android:stretchColumns= "1,2"
        android:layout_width= "match_parent"
        android:layout_height= "match_parent" >
     
    </TableLayout>
     
     
    TableLayout的局部属性(内部空间所有属性)
    android:layout_column="1"       该控件显示在第二列
    android:layout_span="2"     该控件占据2列。
     <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
     
            <Button
                android:layout_column="1"
                android:layout_span="2"
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1" />
     
        </TableRow >
     
     
    TableLayout 计数器

    <?xml version= "1.0" encoding ="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:stretchColumns= "*"
        android:layout_width= "match_parent"
        android:layout_height= "match_parent" >
     
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:gravity="right|center_vertical"
            android:text="90" />
     
        <TableRow
            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="wrap_content"
                android:text="7" />
     
            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="8" />
     
            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="9" />
     
            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="/" />
     
        </TableRow >
     
        <TableRow
            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="wrap_content"
                android:text="4" />
     
            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="5" />
     
            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="6" />
     
            <Button
                android:id="@+id/button8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="*" />
     
        </TableRow >
     
        <TableRow
            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="wrap_content"
                android:text="1" />
     
            <Button
                android:id="@+id/button10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2" />
     
            <Button
                android:id="@+id/button11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="3" />
     
            <Button
                android:id="@+id/button12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="-" />
     
        </TableRow >
     
        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
     
            <Button
                android:layout_span="4"
                android:id="@+id/button13"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="=" />
     
        </TableRow >
     
    </TableLayout>
    stareblankly.cn
  • 相关阅读:
    jquery全屏幻灯轮播焦点图
    PHP curl 上传文件版本兼容问题
    一个网站同一域名不同目录下的文件访问到的cookie值不同是什么原因?
    Linux系统查找清理磁盘大文件方法
    REDIS常用命令
    CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法
    centos6 编译安装nodejs4.3
    centos yum安装php5.6.19 remi源按照
    Mac下用brew搭建PHP(LNMP/LAMP)开发环境
    为什么JAVA要提供 wait/notify 机制?是为了避免轮询带来的性能损失
  • 原文地址:https://www.cnblogs.com/stareblankly/p/4829252.html
Copyright © 2020-2023  润新知