Android中的约束布局
文章目录
- 1 Android中的约束布局
- 1.1 约束布局的重要属性
- 1.2 约束布局示例
1 Android中的约束布局
1.1 约束布局的重要属性
重要属性:
- app:layout_constraintBottom_toBottomO(约束当前view的底部位置)
- app:layout_constraintVertical_bias(垂直偏移量)
xml中<需要使用<
来表示,>需要使用>
来表示。
1.2 约束布局示例
需要实现的效果如下:
需要注意的是对于约束布局我们一般更多的是采用拖拉来进行实现的,xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"android:background="@mipmap/bg"><!--app:layout_constraint方位_to方位Of="?"? : 1. parent 2.引用其他控件id当前控件的某个方位和另一个参照物的某个方位对齐app:layout_constraintLeft_toLeftOf 相当于RelativeLayout的alignLeft属性app:layout_constraintRight_toRightOf 相当于RelativeLayout的alignRight属性app:layout_constraintTop_toTopOf 相当于RelativeLayout的alignTop属性app:layout_constraintBottom_toBottomOf 相当于RelativeLayout的alignBottom属性app:layout_constraintStart_toStartOf 同Left_toLeftOfapp:layout_constraintEnd_toEndOf 同Right_toRightOf当前控件的A侧会在参照物的B侧app:layout_constraintLeft_toRightOf 相当于RelativeLayout的toRightOfapp:layout_constraintRight_toLeftOf 相当于RelativeLayout的toLeftOfapp:layout_constraintTop_toBottomOf 相当于RelativeLayout的belowapp:layout_constraintBottom_toTopOf 相当于RelativeLayout的aboveapp:layout_constraintStart_toEndOf 同Left_toRightOfapp:layout_constraintEnd_toStartOf 同Right_toLeftOfapp:layout_constraintVertical_bias="0.53" 垂直偏移量,0.5在正中间app:layout_constraintHorizontal_bias="0.53" 水平偏移量,0.5在正中间--><TextViewandroid:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="15dp"android:text="红包"android:textColor="#f6d5a8"android:textSize="22sp"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="15dp"android:layout_marginLeft="8dp"android:text=" < 返回"android:textColor="#f6d5a8"android:textSize="22sp"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><!-- < > 左右尖括号--><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="15dp"android:layout_marginRight="8dp"android:text="红包"android:textColor="#f6d5a8"android:textSize="22sp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintTop_toTopOf="parent" /><Buttonandroid:id="@+id/button2"android:layout_width="330dp"android:layout_height="60dp"android:background="@mipmap/btn"android:text="一字千金红包"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.53" /><Buttonandroid:id="@+id/button3"android:layout_width="330dp"android:layout_height="60dp"android:background="@mipmap/btn"android:layout_marginBottom="15dp"android:text="普通红包"app:layout_constraintBottom_toTopOf="@+id/button2"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent" /><Buttonandroid:id="@+id/button4"android:layout_width="330dp"android:layout_height="60dp"android:background="@mipmap/btn"android:layout_marginBottom="15dp"android:text="口令红包"app:layout_constraintBottom_toTopOf="@+id/button3"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent" /><LinearLayoutandroid:id="@+id/linearLayout"android:layout_width="330dp"android:layout_height="60dp"android:background="@mipmap/edit"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/button2"app:layout_constraintVertical_bias="0.389"><EditTextandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:background="@null"android:gravity="center"android:hint="输口令,领红包" /><TextViewandroid:layout_width="90dp"android:layout_height="match_parent"android:gravity="center"android:text="确定"android:textColor="#cccccc"android:textSize="26sp" /></LinearLayout><TextViewandroid:id="@+id/textView4"android:layout_width="wrap_content"android:layout_height="22dp"android:layout_marginStart="8dp"android:layout_marginLeft="8dp"android:layout_marginTop="15dp"android:layout_marginEnd="8dp"android:layout_marginRight="8dp"android:text="口令红包规则"android:textColor="#f6d5a8"android:textSize="18sp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Android中的约束布局相关推荐
- Android中的常见布局
文章目录 1 常见布局 2 创建布局的方式 1 常见布局 Android中的常见布局如下: 线性布局(LinearLayout): 相对布局(RelativeLayout): 帧布局(FrameLay ...
- Android中的网格布局
文章目录 1 Android中的网格布局 1 Android中的网格布局 重要属性: android:rowCount(行数量) android:columnCount (列数量) android:l ...
- Android中的表格布局
文章目录 1 Android中的表格布局 1 Android中的表格布局 重要属性: android:stretchColumns android:shrinkColumns android:coll ...
- Android中的帧布局
文章目录 1 Android中的帧布局 1 Android中的帧布局 首先看下效果: 下面看下xml: <?xml version="1.0" encoding=" ...
- Android中的相对布局
文章目录 1 Android中的相对布局 1.1 相对布局的重要属性 1.2 相对布局示例 1 Android中的相对布局 1.1 相对布局的重要属性 相对于父容器(取值:true/false),如: ...
- Android中动态初始化布局参数以及ConstraintLayout使用中遇到的坑
Android中动态初始化布局以及ConstraintLayout遇到的一个坑 ConstraintLayout是Android中的一个很强大的布局,它通过控件之间的相对定位,来完成一个layout中 ...
- Android 中LayoutInflater(布局加载器)之介绍篇
本文出自博客Vander丶CSDN博客,如需转载请标明出处,尊重原创谢谢 博客地址:http://blog.csdn.net/l540675759/article/details/78099358 前 ...
- Android开发之约束布局平均分布|ConstraintLayout平均分布|约束布局均匀分布|ConstraintLayout均匀分布
老路子先看效果图 1.先画7个小球会全部重叠在一起 <?xml version="1.0" encoding="utf-8"?> <andro ...
- android鸿洋布局,Android基础ConstrainLayout约束布局的介绍和使用
写在前面:之前稍微复杂的设计实现,我们都可能会借助于嵌套实现,我们知道嵌套越多,性能就越低.而我们布局一般都是在xml里面进行实现,拖拽的话估计现在android开发者都不会去使用.为了提升开发者的可 ...
最新文章
- 中文Python:中文编程不是梦
- 用户名 不在 sudoers文件中,此事将被报告
- 我们一直使用的管理系统oner
- IP釋放、清除、以及刷新DNS
- openstack网络指南_性格内向的战术网络指南
- 【本地差分隐私与随机响应代码实现】差分隐私代码实现系列(十三)
- ssm框架中前台html如何接受后台的数据_计算机毕业设计中实现java后台的微信小程序...
- 今天要查一下,如果没有密保手机的号码在使用,怎么更换qq的密保手机
- 国内访问 Atom 源很慢 解决方案
- idea 一键展开所有方法 一键收纳所有方法
- 庖丁解D,游刃有余---Discuz!免费版安全性分析(转)
- KMeans聚类分析实战——如何把城市划分成不同的种类
- leaflet地图鼠标移动画线
- 【软件网每日新闻播报│第9-18期】
- ios真机测试,Ineligible Devices,不可以选中真机
- 02 解方程专题 (各学科:高数、线代、专业课)
- 温州科技职业学院 计算机网络技术,浙江【温州科技职业学院】_计算机网络技术专业建设方案.doc...
- html长方形代码_Graphics绘图,画矩形,长方形(入门级)
- python用四个圆画成花_【元旦手工】最美元旦手工花手工教程,赶紧提前收藏吧!...
- 计算机专业surface pro,surface pro4家庭版和专业版的不同
热门文章
- css 横线_CSS-画一个太极阴阳图
- 【控制】《多智能体系统一致性协同演化控制理论与技术》纪良浩老师-第8章-二阶连续时间多智能体系统加权一致性
- 【任务脚本】0601更新autojs客户端,回顾之前战绩,注意事项淘宝618活动领喵币autojs脚本,向大神致敬...
- 【测试】用示波器抓取红外遥控器NEC信号
- 【中继协助频谱切换】基于中继协助的频谱切换机制的MATLAB仿真
- Error处理:/bin/bash^M: 坏的解释器: 没有该文件或目录(bad interpreter: No such file or directory)...
- Maven和Spring mvc下的页面的跳转与取值
- 【转】Node.js最新Web技术栈(2015年5月)
- Android JNI开发摘录(四)之JNI异常处理
- 《20年后,你靠什么生存(孙继滨)》讲座观后感