Android基础:布局管理器

1.相对布局管理器
android:layout_marginTop=“25dip” //顶部距离
android:gravity=“left” //空间布局位置
android:layout_marginLeft="15dip //距离左边距
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;
android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;
// 指定移动像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft   左偏移的值;
android:layout_marginRight   右偏移的值;
2.线性布局管理器
android:orientation
android:gravity
android: layout_weight
3.帧布局管理器
android:foreground:*设置改帧布局容器的前景图像
android:foregroundGravity:设置前景图像显示的位置
4.表格布局管理器
android:collapseColumns:设置需要被隐藏的列的序号
android:shrinkColumns:设置允许被收缩的列的列序号
android:stretchColumns:设置运行被拉伸的列的列序号
android:layout_column=“1” 该控件显示在第1列
android:layout_span=“2” 该控件占据2列
5.网格布局管理器
android:alignmentMode
说明:当设置alignMargins,使视图的外边界之间进行校准。可以取以下值:
alignBounds – 对齐子视图边界。
alignMargins – 对齐子视距内容。
android:columnCount
说明:GridLayout的最大列数
android:rowCount
说明:GridLayout的最大行数
android:columnOrderPreserved
说明:当设置为true,使列边界显示的顺序和列索引的顺序相同。默认是true。
android:orientation
说明:GridLayout中子元素的布局方向。有以下取值:
horizontal – 水平布局。
vertical – 竖直布局。
android:rowOrderPreserved
说明:当设置为true,使行边界显示的顺序和行索引的顺序相同。默认是true。
android:useDefaultMargins
说明: 当设置ture,当没有指定视图的布局参数时,告诉GridLayout使用默认的边距。默认值是false。
android:layout_column
说明:显示该子控件的列,例如android:layout_column=”0”,表示当前子控件显示在第1列,android:layout_column=”1”,表示当前子控件显示在第2列。
android:layout_columnSpan
说明:该控件所占的列数,例如android:layout_columnSpan=”2”,表示当前子控件占两列。
android:layout_row
说明:显示该子控件的行,例如android:layout_row=”0”,表示当前子控件显示在第1行,android:layout_row=”1”,表示当前子控件显示在第2行。
android:layout_rowSpan
说明:该控件所占的列数,例如android:layout_rowSpan=”2”,表示当前子控件占两行。
android:layout_columnWeight
说明:该控件的列权重,与android:layout_weight类似,例如有GridLayout上两列,都设置android:layout_columnWeight = “1”,则两列各占GridLayout宽度的一半
android:layout_rowWeight
说明:该控件的行权重,原理同android:layout_columnWeight
实例:
注意当布局管理器嵌套时,根布局管理器要有xmlns属性

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.mingrisoft.MainActivity" >
    <!-- 第一条信息 -->
     <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_margin="10dp" >
         <ImageView
             android:id="@+id/ico1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_margin="10dp"
             android:src="@mipmap/v_ico1" />
         <TextView
             android:id="@+id/name1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginTop="10dp"
             android:layout_toRightOf="@+id/ico1"
             android:text="雪绒花"
             android:textColor="#576B95" />
         <TextView
             android:id="@+id/content1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@id/name1"
             android:layout_marginBottom="5dp"
             android:layout_marginTop="5dp"
             android:layout_toRightOf="@+id/ico1"
             android:minLines="3"
             android:text="祝我的亲人、朋友们新年快乐!" />
         <TextView
             android:id="@+id/time1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_below="@id/content1"
             android:layout_marginTop="3dp"
             android:layout_toRightOf="@id/ico1"
             android:text="昨天"
             android:textColor="#9A9A9A" />
          <ImageView
              android:id="@+id/comment1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:layout_below="@id/content1"
              android:src="@mipmap/comment" />
          <ImageView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@mipmap/line" />
     </RelativeLayout>
    <!-- 分隔线 -->
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@mipmap/line" />
    <!-- 第二条信息 -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" >

        <ImageView
            android:id="@+id/ico2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_margin="10dp"
            android:src="@mipmap/v_ico2" />

        <TextView
            android:id="@+id/name2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@id/ico2"
            android:text="淡淡的印象"
            android:textColor="#576B95" />

        <TextView
            android:id="@+id/content2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/name2"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@id/ico2"
            android:minLines="3"
            android:text="奋斗就是每一天都很难,可一年比一年容易。不奋斗就是每一天都很容易,可一年比一年难。怕吃苦的人吃苦一辈子,不怕吃苦的人吃苦一阵子。所以拼着一切代价奔你的前程;拼一个春夏秋冬,赢一个无悔人生!" />

        <TextView
            android:id="@+id/time2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/content2"
            android:layout_marginTop="3dp"
            android:layout_toRightOf="@id/ico2"
            android:text="6小时前"
            android:textColor="#9A9A9A" />

        <ImageView
            android:id="@+id/comment2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/content2"
            android:src="@mipmap/comment" />
    </RelativeLayout>
    <!-- 分隔线 -->
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@mipmap/line" />

</LinearLayout>

猜你喜欢

转载自blog.csdn.net/qq_37282683/article/details/86519330