• Android_layout 布局(二)


    昨天学习了layout 布局的线性布局和相对布局。

    今天我们学习剩余的三个布局,分别是:

    一、帧布局(FrameLayout)

      在这个布局中,所有的子元素都不能被指定放置的位置,它们通通放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。

    注:帧布局和线性布局的区别

      在大体上的用法等等两者还是很相似的。但是有一点两点的根本区别。

      帧布局是有“深度”的,它只追求在这个点上去深入。

      线性布局是有“广度”的,它是向外延展的,他就是一个“面”。

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent" >
     5 
     6     <TextView
     7         android:id="@+id/textView1"
     8         android:layout_width="300dp"
     9         android:layout_height="300dp"
    10         android:text="1" 
    11         android:background="#ff00ff"/>
    12 
    13     <TextView
    14         android:id="@+id/textView2"
    15         android:layout_width="200dp"
    16         android:layout_height="200dp"
    17         android:text="2"
    18         android:background="#00ffff" />
    19 
    20     <TextView
    21         android:id="@+id/textView3"
    22         android:layout_width="100dp"
    23         android:layout_height="100dp"
    24         android:background="#ff0000"
    25         android:text="3" />
    26 
    27 </FrameLayout>
    View Code

    二、绝对布局(AbsoluteLayout)

      1.absoluteLayout 又叫坐标布局,可以直接指定子元素的绝对位置(x,y)

        2.由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差,在屏幕的适配上有缺陷

      3.子控件的属性

      android:layout_x="35dip" 控制当前子类控件的x位置

      android:layout_y="35dip" 控制当前子类控件的y位置

    注:建议最好不要使用绝对布局,我们手机屏幕大小不同,你用这个型号,这个大小的手机定位好的位置,当你换了个手机尺寸不一样的,就会将你的布局打乱,这样很不好。我在这就不演示了。记住,记住,最好不要使用,不利用开发

    三、表格布局(TableLayout)

      表格布局类似于我们html 中的table 元素一样。

     我们来看看他的属性。

    接下来我们做个简单的表格布局的栗子来认识下这个表格布局。计算器

    <?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="*" >
            <EditText
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:gravity="center_vertical|right"
                android:layout_weight="1"/>
        <TableRow 
                android:layout_weight="1">
    
            <Button
                android:id="@+id/btn7"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="7" />
    
            <Button
                android:id="@+id/btn8"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="8" />
    
            <Button
                android:id="@+id/btn9"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="9" />
    
            <Button
                android:id="@+id/btnchu"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="/" />
        </TableRow>
    
        <TableRow 
                android:layout_weight="1">
    
            <Button
                android:id="@+id/btn4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="4" />
    
            <Button
                android:id="@+id/btn5"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="5" />
    
            <Button
                android:id="@+id/btn6"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="6" />
    
            <Button
                android:id="@+id/btncheng"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="*" />
        </TableRow>
    
        <TableRow 
                android:layout_weight="1">
    
            <Button
                android:id="@+id/btn1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="1" />
    
            <Button
                android:id="@+id/btn2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="2" />
    
            <Button
                android:id="@+id/btn3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="3" />
    
            <Button
                android:id="@+id/btnjian"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="-" />
        </TableRow>
    
        <TableRow 
                android:layout_weight="1">
    
            <Button
                android:id="@+id/btn0"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="0" />
    
            <Button
                android:id="@+id/btndian"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="." />
    
            <Button
                android:id="@+id/btnjia"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="+" />
    
            <Button
                android:id="@+id/btndeng"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="=" />
        </TableRow>
    
        <TableRow 
                android:layout_weight="1">
    
            <Button
                android:id="@+id/clear"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_span="4"
                android:text="clear" />
        </TableRow>
    
    </TableLayout>
    View Code

    效果显示是这样的。

    关于android 的 layout 布局,就暂时讲这些,关于这几大布局的属性,大家有空都可以去试试,多练习下布局的排布,综合起来,排布一个页面什么的。属性每个布局中的属性。

    今天就先到这,欢迎大家一起学习。

  • 相关阅读:
    mysql授权GRANT ALL PRIVILEGES
    MySQL修改root密码的多种方法
    javaagent
    JavaAgent 应用(spring-loaded 热部署)
    JavaAgent入门
    java运行jar命令提示没有主清单属性
    连接到 redis 服务
    PHP中的socket TCP编程
    Memcached 与 Redis 区别
    rc.local配置
  • 原文地址:https://www.cnblogs.com/heyhhz/p/6095210.html
Copyright © 2020-2023  润新知