学习Layout总结

学习Layout总结

一、RelativeLayout(相对布局)
相对布局有两种,一种是相对容器而言,另一种是相对控件而言。
*下面是对控件的一种
这里写图片描述

<ImageView
      android:layout_width="100dp"
    android:layout_height="100dp"
    app:srcCompat="@drawable/smile1"
    android:id="@+id/imageView"
    android:layout_centerInParent="true"/>

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    app:srcCompat="@drawable/rabbit4"
    android:layout_below="@+id/imageView"
    android:layout_alignLeft="@+id/imageView2"
    android:layout_alignStart="@+id/imageView2"
    android:layout_marginTop="24dp"
    android:id="@+id/imageView3" />

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    app:srcCompat="@drawable/rabbit2"
    android:layout_alignTop="@+id/imageView4"
    android:layout_toRightOf="@+id/imageView"
    android:layout_toEndOf="@+id/imageView"
    android:layout_marginLeft="33dp"
    android:layout_marginStart="33dp"
    android:id="@+id/imageView5" />

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    app:srcCompat="@drawable/rabbit1"
    android:id="@+id/imageView4"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/imageView"
    android:layout_toStartOf="@+id/imageView"
    android:layout_marginRight="41dp"
    android:layout_marginEnd="41dp" />

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    app:srcCompat="@drawable/rabbit3"
    android:id="@+id/imageView2"
    android:layout_marginBottom="25dp"
    android:layout_above="@+id/imageView"
    android:layout_alignLeft="@+id/imageView"
    android:layout_alignStart="@+id/imageView"
    android:layout_marginLeft="13dp"
    android:layout_marginStart="13dp" />

二、LinearLayout(线性布局)
*在UI开发中,线性布局默认为水平显示,如果想要设置垂直,用属性orientation;
*weight表示权重
*控件布局中对齐方式用layout_gravity,文字在布局中对齐方式用gravity

这里写图片描述

<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:layout_weight="1"
    android:layout_marginTop="10dp"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ababab"
    android:layout_weight="1"
    android:layout_marginTop="10dp"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0000ff"
    android:layout_weight="1"
    android:layout_marginTop="10dp"/>
<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00ff00"
    android:layout_weight="1"
    android:layout_marginTop="10dp"/>

<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff0000"
    android:layout_weight="1"
    android:layout_marginTop="10dp"/>

三、TableLayout(表格布局)
*每一行用TableRow
这里写图片描述

<TableRow
>
<EditText android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Account:"/>
<TextView android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:hint="Input  your  account"
    android:gravity=""
    android:layout_weight="1"/>
</TableRow>

 <TableRow
    >
    <EditText android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password:"/>
    <TextView android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/>
</TableRow>

<TableRow>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login"
        android:layout_weight="1"
        android:id="@+id/button" />
</TableRow>

四、GridLayout(网格布局)

五、FrameLayout(帧布局)
*帧布局在局面上是一帧一帧显示的;
*帧布局在子控件默认是左上角对齐;
这里写图片描述

<Button
    android:text="Button1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:id="@+id/button" />

<Button
    android:text="Button2"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:id="@+id/button2" />

六、AbsoluteLayout(相对布局)
*可以确定准确的坐标值,代码是:
android:laoyout_x 确定水平的位置;
android:laoyout_y 确定竖直的位置;

以上就是我对六个布局的了解,希望以后更深入了解。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值