美文网首页
四种基本布局

四种基本布局

作者: TTTqiu | 来源:发表于2016-04-21 15:38 被阅读67次

一、LinearLayout


LinearLayout 又称作线性布局,这个布局会将它所包含的控件在线性方向上依次排列。通过 android:orientation 属性指定排列方向是 vertical(垂直)或 horizontal(水平),默认 horizontal。

  • android:layout_weight

允许我们使用比例的方式来指定控件的大小。注意** android:layout_weight 设为 0 **比较规范。


二、RelativeLayout


RelativeLayout 又称作相对布局,它可以通过相对定位的方式让控件出现在布局的任何位置。

android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_above="@id/button3"
android:layout_below="@id/button3"
android:layout_toLeftOf="@id/button3"
android:layout_toRightOf="@id/button3"

三、FrameLayout


FrameLayout 这种布局没有任何的定位方式,所有的控件都会摆放在布局的左上角


四、TableLayout


TableLayout 允许我们使用表格的方式来排列控件。

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1" >
    <TableRow>
        <TextView
            android:layout_height="wrap_content"
            android:text="Account:" />
        <EditText
            android:id="@+id/account"
            android:layout_height="wrap_content"
            android:hint="Input your account" />
    </TableRow>
    <TableRow>
        <TextView
            android:layout_height="wrap_content"
            android:text="Password:" />
        <EditText
             android:id="@+id/password"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    </TableRow>
    <TableRow>
        <Button
             android:id="@+id/login"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="Login" />
    </TableRow>
</TableLayout>
  • 使用 android:layout_span="2" 让登录按钮占据两列的空间。
  • 在 TableRow 中无法指定控件的宽度。这时使用 android:stretchColumns,它允许将 TableLayout 中的某一列进行拉伸,以达到自动适应屏幕宽度的作用。android:stretchColumns="1"

相关文章

  • 四种基本布局

    一、LinearLayout LinearLayout 又称作线性布局,这个布局会将它所包含的控件在线性方向上依次...

  • CSS布局

    基本上,有四种可选的布局类型:1.固定宽度布局2.自适应布局3.弹性布局4.混合布局 1.固定布局以像素为单位,外...

  • bootstrap网格系统

    基本用法:网格系统用来布局,其实就是列的组合。Bootstrap框架的网格系统中有四种基本的用法。由于Bootst...

  • UI布局初试three---四种基本布局

    版权声明:欢迎转载,转载请注明出处。 如果本文帮助到你,本人不胜荣幸,如果浪费了你的时间,本人深感抱歉。如果有什么...

  • 布局

    今天学习了安卓的四种布局方式 线性布局 相对布局 帧布局 百分比布局

  • Android零基础入门第30节:两分钟掌握FrameLayou

    前面学习了线性布局、相对布局、表格布局,那么本期来学习第四种布局——FrameLayout帧布局。 一、认识Fra...

  • Android零基础入门第31节:几乎不用但要了解的Absolu

    前面几期基本学习了Android开发中常用的四种布局,之所以把AbsoluteLayout放在后面来学习,是由于在...

  • Android UI的四种基本布局

    布局是一种可用于放置很多控件的容器,它可以按照一定的规律调整内部控件的位置,从而编写出精美的界面。当然,布局的内部...

  • CSS2-3的盒模型

    Css2定义了四种布局模式 1) 块布局:呈现文档的布局模式 2) 行内布局:呈现文本的布局模式 3) 表格布局:...

  • 全脑课程里的脑波

    四种基本脑波 α波(ALPHA/α wave)是四种基本脑波之一。 四种基本脑波是:δ波(DELTA/δ wave...

网友评论

      本文标题:四种基本布局

      本文链接:https://www.haomeiwen.com/subject/hvptrttx.html