Android ConstraintLayout 约束布局

  • 线性布局(LinearLayout)

    重要属性:

     android:orientation(方向)
     android:layout_weight(权重)
    
  • 相对布局 (RelativeLayout)

    依照参照物定位的布局,较为灵活的布局

     android:layout_alignParentRight:和父容器的右侧对齐(True or False)
     android:layout_centerHorizontal:在父容器中水平居中(True or False)
     android:layout_toLeftOf:
     android:layout_alignRight:  	
    
  • 帧布局 (FrameLayout)

     android:layout_gravity(控件重力)
     android:foreground(前景)
     android:foregroundGravity(前景重力)
    
  • 表格布局 (TableLayout)

     android:strechColums设置可伸展的列
     android:shrinkColums设置可收缩的列
     android:collapseColumns设置可隐藏的列
    
  • 网格布局 (GirdLayout)

     android:rowCount行数量
     android:columnCount列数量
     android:layout_row位于第几行
     android:layout_rowSpan跨几行
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio的约束布局是一种强大而灵活的布局方式,它允许您以声明性的方式定义视图之间的关系。以下是使用约束布局的一些基本步骤: 1. 在布局文件中使用`ConstraintLayout`作为根视图。在XML文件中,您可以这样声明一个约束布局: ``` <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 在这里添加其他视图 --> </androidx.constraintlayout.widget.ConstraintLayout> ``` 2. 定义视图之间的约束关系。您可以通过拖动和放置视图来在设计编辑器中设置约束,也可以在XML文件中手动编写约束。例如,要将一个按钮位于父布局顶部,并与左右边缘有10dp的间距,您可以这样定义约束: ``` <Button android:id="@+id/myButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My Button" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_marginStart="10dp" app:layout_marginEnd="10dp"/> ``` 3. 可选地,您还可以使用链(chains)和辅助对象(guidelines)来进一步定义视图之间的关系,以及在不同屏幕尺寸下的自适应布局约束布局的优势在于它可以适应各种屏幕尺寸和方向,并且可以减少嵌套布局的需要。您可以通过在Android Studio的设计编辑器中直观地操作视图和约束,或者手动编辑XML文件来创建约束布局。要了解更多关于约束布局的信息和用法,请参阅Android官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值