• 第24讲 UI_布局 之帧布局 表格布局 绝对布局


    第24讲 UI_布局 之帧布局 表格布局 绝对布局

    3. FrameLayout(帧布局)

    帧布局是从屏幕的左上角(0,0)坐标开始布局,多个组件层叠排序,后一个组件总会将前一个组件所覆盖,除非最后一个组件是透明的。


    <Button   

            android:layout_width="fill_parent"   

           android:layout_height="wrap_content"  

            android:text="Button1"   />  

        <Button   

            android:layout_width="wrap_content"   

           android:layout_height="fill_parent"  

            android:text="Button2"   />  

        <Button   

            android:layout_width="wrap_content"  

            android:layout_height="wrap_content"   

           android:text="Button3"   /> 

     此布局通常用于软件的初始化页面,启动页面等。

    属性名称

    对应方法

    说明

    android:foreground

    setForeground(Drawable)

    设置该帧布局容器的前景图像

    android:foregroundGravity

    setForegroundGravity(int)

    设置前景图像显示的位置

    4. TableLayout(表格布局)

    TableLayout(表格布局),顾名思义就是像表格一样布局,以行、列的方式布局子组件。TableLayout使用TableRow对象来定义多行。每个TableRow就是一行


    <TableRow>  

           <Button android:text="Button1"/> 

          <Button android:text="Button2"/> 

           <Button android:text="Button3"/>      </TableRow>  

    <TableRow>  

            <Button android:text="Button4"/>  

            <Button android:text="Button5"/>   

           <Button android:text="Button6"/>      </TableRow>  

     <TableRow>  

           <Button android:text="Button7"/>     

          <Button android:text="Button8"/>     

         <Button android:text="Button9"/>      </TableRow>  

     TableLayout中也有几个常用属性:

    (1) android:shrinkColumns属性:以0为序,当TableRow里面的控件布满布局时,指定列自动延伸以填充可用部分;当TableRow里面的控件还没有布满布局时,shrinkColumns不起作用。

    (2) android:strechColumns:以第0行为序,指定列对空白部分进行填充

    (3) android:collapseColumns:以0行为序,隐藏指定的列

    (4) android:layout_column:以0行为序,设置组件显示指定列。

    (5) android:layout_span:以第0行为序,设置组件显示占用的列数。

     

     //16个按钮

    <Button  android:id="@+id/one"        android:text="1"/>

    <Button          android:id="@+id/two"          android:text="2"/>

    <Button          android:id="@+id/three"      android:text="3"/>

    <Button          android:id="@+id/devide"     android:text="/"/>

    <Button          android:id="@+id/four"          android:text="4"/>

    <Button          android:id="@+id/five"          android:text="5"/>

    <Button          android:id="@+id/six"             android:text="6"/>

    <Button          android:id="@+id/multiply"   android:text="×"/>

    <Button          android:id="@+id/seven"       android:text="7"/>

    <Button          android:id="@+id/eight"        android:text="8"/>

    <Button          android:id="@+id/nine"         android:text="9"/>

    <Button          android:id="@+id/minus"        android:text="-"/>

    <Button          android:id="@+id/zero"         android:layout_columnSpan="2"   android:layout_gravity="fill"android:text="0"/>

    <Button          android:id="@+id/point"        android:text="."/>

    <Button          android:id="@+id/plus"          android:layout_rowSpan="2"  android:layout_gravity="fill"android:text="+"/>

    <Button          android:id="@+id/equal"       android:layout_columnSpan="3"  android:layout_gravity="fill" android:text="="/>

    5. AbsoluteLayout(绝对布局)

    AbsoluteLayout(绝对布局),组件的位置可以准确的指定其在屏幕的x/y坐标位置。虽然可以精确的去规定坐标,但是由于代码的书写过于刚硬,使得在不同的设备,不同分辨率的手机移动设备上不能很好的显示应有的效果,所以此布局不推荐使用


    <Button   

            android:layout_width="wrap_content"  

            android:layout_height="fill_parent"  

            android:text="Button1"  

            android:layout_x="100dp"  />  

        <Button   

            android:layout_width="fill_parent"  

            android:layout_height="wrap_content"  

            android:text="Button2"  

            android:layout_y="100dp"   /> 

  • 相关阅读:
    [你必须知道的.NET]第二十一回:认识全面的null
    《你必须知道的.NET》,内容简介
    [IT史记]开篇:盖茨本纪之离歌
    《你必须知道的.NET》,封面
    《博客园精华集》,CLR/C#分册征求意见稿
    [开发故事]第二回:LINQ来了,先忘记foreach
    《你必须知道的.NET》,封底
    [不得不转载]一个时代的结束:微软盖茨的人生掠影
    [技术速递]MSDN在线改版,新风格新体验
    《你必须知道的.NET》,勘误支持
  • 原文地址:https://www.cnblogs.com/anyuan9/p/6171598.html
Copyright © 2020-2023  润新知