ConstraintLayout

本文介绍了Android Studio中的ConstraintLayout,重点讨论了百分比布局、引导线的使用、自动填充宽高以及纵横比的概念。通过实例展示了如何创建响应式布局,以适应不同设备和分辨率。
摘要由CSDN通过智能技术生成

环境:
Android studio,jdk1.8,API 28,Android 9.0
接触缘由:
由eclipse改用Android studio,突然发现RelativeLayout被替换成了ConstrainLayout,有很多不习惯的地方,从头学习一下,也记录一下。

基础

名字:constraintLayout 约束布局
:命名空间 app
出生年/地:2006年谷歌I/O退出
年龄说明:在项目build.gradle中声明
受到约束:其他视图,父容器(parent),基准线(Guideline)
优点:降低布局的层级, 加快渲染速度,适合复杂布局

基本五官

layout_constrant[本源位置]_[目标位置]="[目标ID]"

视觉效果

app:layout_constraintBottom_toTopOf="@id/button1"
将当前view的底部对其到button1的顶部

eg:实现底部导航栏
在这里插入图片描述

<?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"
    android:id="@+id/constraintLayout">


    <TextView
        android:id="@+id/tab1"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:text="tab1"
        android:textColor="@color/colorWhite"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/tab2" />

    <TextView
        android:id="@+id/tab2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:gravity="center"
        android:text="tab2"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toRightOf=<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值