Android ConstraintLayout约束布局的居中
Android ConstraintLayout约束布局的居中
xml代码:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.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"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_red_light" android:text="text1:顶部水平居中" android:textColor="@android:color/white" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_red_light" android:text="text2:位于text1下且水平居中" android:textColor="@android:color/white" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/text1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_green_light" android:text="水平居中,且居于text2下" android:textColor="@android:color/white" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/text2" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_red_light" android:text="居中位于底部" android:textColor="@android:color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/holo_blue_bright" android:text="全局居中" android:textColor="@android:color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
输出结果如图:

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
iOS动画开发之一——UIViewAnimation动画的使用
本文转载自 https://yq.aliyun.com/articles/39230?spm=a2c4e.11155435.0.0.5b7d5fd1zU7j4d iOS动画开发之一——UIViewAnimation动画的使用 一、简介 一款APP的成功与否,除了完善的功能外,用户体验也占有极大的比重,动画的合理运用,可以很好的增强用户体验。iOS开发中,常用的动画处理有UIView动画编程和核心动画编程,其中UIView动画使用简便,开发中应用十分广泛。这篇博客,主要讨论UIView的动画使用。 二、UIView动画的几个方法 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations; 这个是参数最少的一个方法,我们可以通过设置一个时间和block块来完成动画,时间参数是动画执行的时长,block块中为要执行的动画动作,具体可以执行那些动作,我们会在后面说。例如在1S内将view渐变透明: [UIView animateWithDuration:1 animati...
- 下一篇
【阿里聚安全·安全周刊】 全美警局已普遍拥有破解 iPhone 的能力 | 女黑客破解任天堂Switch,称硬件漏洞无法修复
本周的七个关键词:破解 iPhone丨女黑客破解任天堂丨假的身份证丨扫黄打非丨华盛顿特区发现手机间谍设备丨Telegram被俄罗斯监管机构告上法庭丨价值5万美金的Firefox浏览器漏洞 -1-【iOS】全美警局已普遍拥有破解 iPhone 的能力 来源:MacX ------------------------------------------------------ 来自 Motherboard 的报道称,目前全美范围内的当地警署以及联邦机构都可以很轻易的获取到解锁iPhone的专用工具,绕过加密手段轻松解锁嫌疑人的 iPhone,即使设备更新至最新版的操作系统也没有问题。 执法机关使用的是一种被称作 GrayKey 的解密工具,据称可以在数小时内解锁 4 位 iPhone 密码,不过 6 位密码可能需要花上
相关文章
文章评论
共有0条评论来说两句吧...