ConstraintLayout 学习

ConstrainLayout 基础教程,android插件化开发指南pdf 纵向:Top、Bottom、Baseline(文本底部的基准线) 根据布局中的其他元素或视图, 确定View在屏幕中的位置, 受到三类约束, 即其他视图, 父容器(parent), 基准线(Guideline). layout_constraint[本源位置]_[目标位置]="[目标ID]" 例如: app:layout_constraintBottom_toBottomOf="@+id/constraintLayout" 约束当前View的底部至目标View的底部, 目标View是constraint. 阅读详情

ConstraintLayout官网学习地址

       最近发现使用ConstraintLayout这个布局方式的公司越来越多了,趁着最近比较空闲,利用空余时间来学习应用下,主要是根据官方的文档来进行分析理解~

一、ConstraintLayout 官方文档的理解学习

    ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). It's similar to RelativeLayout in that all views are laid out according to relationships between sibling views and the parent layout, but it's more flexible than RelativeLayout and easier to use with Android Studio's Layout Editor.

     All the power of ConstraintLayout is available directly from the Layout Editor's visual tools, because the layout API and the Layout Editor were specially built for each other. So you can build your layout with ConstraintLayout entirely by drag-and-dropping instead of editing the XML.

      ConstraintLayout 用简单的view来创造复杂和大型的布局场景,和RelativeLayout比较类似(即就是父控件以及子控件间的依赖关系,就不详细介绍了)但是ConstraintLayout比RelativeLayout更灵活好用,可以在可视化的工具栏来拖拽这个控件进行布局构建,在Android Studio 2.0往上默认使用的就是这个布局。

约束Constraint 的概述:

     Constraint ,定义视图在ConstraintLayout中的位置,必须给视图view添加一个或者多个水平和垂直约束,每个约束相当于这个视图在ConstraintLayout中沿着垂直方向或者水平方向的与其他视图之间的对齐等约束关系。

图一    这个图中,视图C只添加了水平约束,没有垂直约束。图中和视图A之间建立了约束关系,C的左边和右边位置分别和A对齐,但是没有垂直约束,所以显示在屏幕的顶部位置。

 

 

图二      这个图解决上述图中出现的问题,图C添加了一个垂直方向的约束,在A的底部,也实现了最终想要的视图效果。

 

 

二、ConstraintLayout 在项目中的应用

1、项目中的添加

 确认项目的build.gradle 文件中是否有maven.google.com 仓库,若是没有添加这个仓库:

repositories {
    google()
}

以依赖的形式把这个库添加到同一个build.gradle文件中:

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'//示例版本,非最新版本
}

Sync Project with Gradle Files同步,就可以将这个库添加到项目中了。

2、布局转换

      以前开发的时候使用的是其他的布局,如果需要所有的项目布局都使用依赖布局,我们旧的布局不需要我们一一去更改,有更智能的转换方式:

旧布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="38dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/thread_btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="线程一写入" />

        <Button
            android:id="@+id/thread_btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="线程二写入" />

        <Button
            android:id="@+id/Thread_query"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="查询所有" />

    </LinearLayout>


</RelativeLayout>

a/ 切换到Android Studio 布局中 Design ;

b/ 找到Component Tree 工具栏,在需要转换的视图(这里需要转换RelativeLayout)上右击选择Convert RelativeLayout to ConstraintLayout

           

3、添加或者删除约束

1)、添加约束

最简单的方式,可以在布局的Design视图窗口进行简单的拖拽来实现约束:

a/ 在Palwtte窗口拖拽合适控件view到视图编辑窗口;

b/ 在 ConstraintLayout 中看到这个控件view 可以看到一个边框,四个角可以拉动调整大小,四边中间有圆形的句柄可以拖动来添加约束关系;

c/ 点击圆形句柄然后拖拽可以添加不同的约束关系,具体可以参考下面两幅图,图一是给父布局添加约束,图二是两个子控件之间的约束。

图一:父布局约束
图二:子控件间的约束

   

@ 添加约束需要注意的点:

  • 每个view都必须有至少两个约束:一个水平方向和一个垂直方向的约束;
  • 添加约束仅仅在同一个水平方向的view 来添加,比如一个view的垂直方向只能和另一个view的垂直方向来添加约束;
  • 每一个约束句柄仅仅可以用在一个约束上,但是可以添加多个约束在同一个点。

2)、删除约束

删除约束很简单,需要删除哪个控件的约束,直接选中这个控件右下角显示 按钮,直接点击就可以删除这个控件的约束了。是不是很简单~

3)、约束图标学习

   Align:对齐,可以选择相对于布局对齐还是其他view对齐方式

  Edit Baseline:基线对齐,每个view的基线可以拖拽和其他view基线对齐

  Guidelines:可以选择添加水平基准线(Add Vertical Guideline)还是垂直(Add Horizontal Guideline)的,这线可以隐藏,可以拖动位置,可以给view添加相对于这条基准线的约束。

   约束的具体也可以在编辑视图的Properties窗口来进行调节。

    视图尺寸调节:使用这个最好宽高至少有一个的属性是match constraints (0dp);

    视图宽高模式:   Fixed ——  宽高设置具体 dp 值

                                 Wrap Content —— 宽高设置wrap_content

                                 Match Constraints  —— 宽高设置0dp

    ratio:宽高比, 要使用这个属性,宽高至少有一个设置为match constraints

 

Notes: 不能在ConstraintLayout中用match_parent ,替代是match constraints<0dp>。

4)双向约束链

一组视图view在同一条chain上,互相之间存在约束关系,一般有以下四种模式:

a/ Spread:默认情况,一组中的几个视图的均匀分布;

b/  Spread inside:一组视图中的第一个和最后一个视图分别在chain 的首端和末端,其他视图均匀分布;

c/ Weighted:类似以LinearLayout 中的weight  权重适配,在约束布局中使用 layout_constraintHorizontal_weight 和 layout_constraintVertical_weight 进行权重的分配。

d/   Packed:一组视图排列在一个链接上,彼此之间没有间隔。

   双向约束链的模式选择,即可以切换以上四种情况模式。

app:layout_constraintHorizontal_chainStyle="packed"

5)自动添加约束

 Autoconnect  自动添加约束,默认不开启,开启后控件在界面中会自动添加约束,但不一定是项目需要的约束;

 Infer Constraints  我们可以将控件拖拽到界面大体位置上,再点击会自动添加控件位置关系的约束

三、ConstraintLayout 使用

可视化操作使用可以参考郭霖大神的 《Android新特性介绍,ConstraintLayout完全解析》

* layout_constraintLeft_toLeftOf          // 左边左对齐
* layout_constraintLeft_toRightOf         // 左边右对齐
* layout_constraintRight_toLeftOf         // 右边左对齐
* layout_constraintRight_toRightOf        // 右边右对齐
* layout_constraintTop_toTopOf            // 上边顶部对齐
* layout_constraintTop_toBottomOf         // 上边底部对齐
* layout_constraintBottom_toTopOf         // 下边顶部对齐
* layout_constraintBottom_toBottomOf      // 下边底部对齐
* layout_constraintBaseline_toBaselineOf  // 文本内容基准线对齐
* layout_constraintStart_toEndOf          // 起始边向尾部对齐
* layout_constraintStart_toStartOf        // 起始边向起始边对齐
* layout_constraintEnd_toStartOf          // 尾部向起始边对齐
* layout_constraintEnd_toEndOf            // 尾部向尾部对齐

 

layout_constraintXXX_toYYYOf="CCC"  :  控件的 XXX边 和 控件CCC 的 YYY边 对齐。

1、居中

1)、屏幕中居中显示

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="second"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@android:color/holo_red_light"
        android:gravity="center"
        android:text="Center"
        android:textColor="@android:color/white"
        android:textSize="16sp"
        app:layout_constraintBottom_toTopOf="@id/btn1"
        app:layout_constraintLeft_toRightOf="@id/btn1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

2)、控件的右上角空白区域居中显示

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="second"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@android:color/holo_red_light"
        android:gravity="center"
        android:text="Center"
        android:textColor="@android:color/white"
        android:textSize="16sp"
        app:layout_constraintBottom_toTopOf="@id/btn1"
        app:layout_constraintLeft_toRightOf="@id/btn1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

 

2、偏移量

app:layout_constraintVertical_bias="0.6"  //在垂直方向向下的偏移量为 60%
app:layout_constraintHorizontal_bias="0.3"  //在水平方向向右的偏移量为 30%

 

3、宽高比 ratio

宽高比设置图

 

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="60dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_purple"
        app:layout_constraintDimensionRatio="2:1"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/iv1"
        android:layout_width="60dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_purple"
        app:layout_constraintDimensionRatio="w,2:1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:layout_width="60dp"
        android:layout_height="0dp"
        android:layout_marginTop="30dp"
        android:background="@android:color/holo_purple"
        app:layout_constraintDimensionRatio="h,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/iv1" />

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="@android:color/holo_red_light"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="2:1"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/iv3"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="@android:color/holo_red_light"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="w,2:1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_marginTop="90dp"
        android:background="@android:color/holo_red_light"
        app:layout_constraintDimensionRatio="h,2:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/iv2" />


    <ImageView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_orange_dark"
        app:layout_constraintBottom_toBottomOf="iv2"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintLeft_toRightOf="@id/iv2"
        app:layout_constraintRight_toLeftOf="@id/iv3"
        app:layout_constraintTop_toTopOf="@id/iv2" />

</android.support.constraint.ConstraintLayout>

使用 layout_constraintDimensionRatio 属性,至少需要设置宽度或者高度为 0dp,宽高的尺寸比例可以通过“float值”或者“W:H”的形式来设置。

分析: layout_width : 0dp   + layout_height : 60dp,设置 ratio : "2:1" 以及  "w,2:1" 效果是一样的,都是宽是高的二倍 ;

                                                                                    设置 ratio : "h,2:1"  则是以高作为基准,即高是宽的二倍。

          layout_width : 60dp + layout_height: 0dp,  设置 ratio : "2:1" 以及 "h,2:1" 效果是一样的,都是宽是高的二倍;

                                                                              设置 ratio : "w,2:1" 则是以宽作为基准,即高是宽的二倍。

使用 layout_constraintDimensionRatio 属性,宽度和高度都设置为 0dp, 会使用满足所有约束条件以及宽高比的最大值尺寸。

 

4、类似 LinearLayout  的权重 layout_weight 设置宽高占比

垂直方向比重设置
<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_red_light"
        android:gravity="center"
        android:text="first"
        app:layout_constraintBottom_toTopOf="@id/tv2"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_weight="1" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_orange_light"
        android:gravity="center"
        android:text="second"
        app:layout_constraintBottom_toTopOf="@id/tv3"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv1"
        app:layout_constraintVertical_weight="1.5" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:text="third"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv2"
        app:layout_constraintVertical_weight="1" />


</android.support.constraint.ConstraintLayout>

 

 

水平方向的比重设置
水平方向的比重设置

 

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@android:color/holo_red_light"
        android:gravity="center"
        android:text="first"
        app:layout_constraintHorizontal_weight="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/tv2"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@android:color/holo_orange_light"
        android:gravity="center"
        android:text="second"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toRightOf="@+id/tv1"
        app:layout_constraintRight_toLeftOf="@+id/tv3"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:text="third"
        app:layout_constraintHorizontal_weight="0.8"
        app:layout_constraintLeft_toRightOf="@+id/tv2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

 

5、指示线Guideline  

     定位的时候也可以使用Guideline 来进行位置的定位,Guideline 是View的子类,使用方式和普通View相同,但是有以下优点:

  • 宽度和高度均是为0
  • 只是用来定位,但是是不可见的 View.Gone
用Guideline 实现控件的位置定位
<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.Guideline
        android:id="@+id/guideline1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="40dp" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:layout_constraintLeft_toRightOf="@id/guideline1"
        app:layout_constraintTop_toBottomOf="@id/guideline2"
        android:background="@android:color/holo_purple" />

</android.support.constraint.ConstraintLayout>

6、Chains 链

Chain 链比较难描述,它是一种特殊的约束,可以为多个通过 chain 链连接的 View 来分发剩余空间位置,类似于 LinearLayout 中的权重比 weight 属性,但 Chains 链要强大得多

如果几个View之间通过双向连接而互相约束对方的位置,那么将其视为链条,例如下面代码呈现的可以称之为链条。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@android:color/holo_red_light"
        android:gravity="center"
        android:text="first"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintHorizontal_weight="0.5"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/tv2"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@android:color/holo_orange_light"
        android:gravity="center"
        android:text="second"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toRightOf="@+id/tv1"
        app:layout_constraintRight_toLeftOf="@+id/tv3"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:text="third"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintHorizontal_weight="0.8"
        app:layout_constraintLeft_toRightOf="@+id/tv2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

 app:layout_constraintHorizontal_chainStyle="XXX"  , 可以设置以下不同模式,实现不同的效果:

* spread - 元素将被展开(默认样式) 
* weighted 加权链 - 在spread 或者 spread_inside 模式下,如果某些小部件设置为MATCH_CONSTRAINT,设置水平或者垂直    方向的权重比例,则它们将拆分可用空间 
* spread_inside - 类似,但链的端点将不会扩展 
* packed - 链的元素将被打包在一起。 孩子的水平或垂直偏差属性将影响包装元素的定位

@margin  : 如果设置margin,整条链有这个边距效果。

 

四、小结

        系统看了官方文档再参考了相关博客算是把ConstraintLayout的相关知识点基本捋了一遍,相对于RelativeLayout 和 LinearLayout 来说更加好用高效,嵌套层级相对较少。ConstraintLayout 约束基本通过layout_constraintXXX_toYYYOf 属性来进行约束对齐,引入了Guideline 和 Chains  ,更好进行约束。

bug:

       在项目运行的时候,位置的依赖我一直使用的@id/XXX,但是我们也知道如果实在该控件下面的控件依赖会报错,找不到这个依赖资源,这次使用constraintlayout 的时候就犯了这个错误,但是把它改为@+id/XXX就行了,不存在找不到控件资源的错误。以前习惯了一直都是@+id/ 是给控件添加id , @id/是来处理位置依赖关系,现在看来@+id/也是可以处理依赖关系的。。。

Android ConstraintLayout布局使用详解 Android ConstraintLayout是谷歌推出替代PrecentLayout的组件。支持相对布局、线性布局、帧布局,笔者看来更像是FrameLayout 、LinearLayout、RelativeLayout三者的结合体,并且比这三者更强大的是实现了百分比布局,大家都知道安卓碎片严重,使用百分比适配,那么将彻底解决适配问题。 本文将教会你如何使用此控件。 一、当作Relative... 阅读详情

相关推荐

ConstraintLayout——约束性布局学习

ConstraintLayout简介 Constraint Layout是Google在2016年的Google I/O大会上提出的一个可以灵活控制子控件的位置和大小的新布局。并且其号称可以实现布局最大程度的扁平化。 ConstraintLayout优点 我们知道项目中的布局嵌套问题对我们的项目性能有着不小的威胁。布局能实现扁平化的话会让软件性能得到很大的提升。所以我们在开发过程中都会尽...

自由奔跑的风 1万+

约束布局ConstraintLayout看这一篇就够了

目录 1.介绍 2.为什么要用ConstraintLayout 3.如何使用ConstraintLayout 3.1 添加依赖 3.2 相对定位 3.3 角度定位 3.4 边距 3.5 居中和偏移 3.6 尺寸约束 3.7 链 4.辅助工具 4.1 Optimizer 4.2 Barrier 4.3 Group 4.4 Placeholder 4.5.Guideline 5.总结 1.介绍 约...

weixin_34167819的博客 3667

从零开始学嵌入式之STM32——1.什么是STM32

它是ST公司推出的一系列单片机的统称。ST----指的是ST公司----意法半导体。意法半导体,成立于1987年,是由意大利的SGS微电子公司和法国的Thomson半导体公司合并而成。ARM目前主要是ARM架构处理器及外围组件的电路设计方案,知识产权授权的形式收取费用,其他公司根据ARM的方案设计出CPU产品。,它以应用为核心,软硬件可裁剪,旨在实现对设备的控制、监测或辅助功能,区别于通用计算机(如 PC、服务器)的 “一机多用” 属性。在嵌入式领域,目前主流的是cortex-M3内核推出的芯片。

qshdyy的博客 1855

ConstraintLayout(约束布局)使用详解

ConstraintLayout 是一个使用“相对定位”灵活地确定微件的位置和大小的一个布局,在 2016 年 Google I/O 中面世,它的出现是为了解决开发中过于复杂的页面层级嵌套过多的问题——层级过深会增加绘制界面需要的时间,影响用户体验,以灵活的方式定位和调整小部件。从 Android Studio 2.3起,创建layout文件就已经是默认ConstraintLayout了,但是尽管Google如此大力推这项技术,但在当时很少有人使用,近些年逐渐被大家拿起来,啊真香!(此处无图胜有图)。

一个IT人的技术成长历程。 9475

VMware Workstation 17 Pro 保姆级教程:手把手教你安装银河麒麟 Kylin V10 SP3 国产系统

本文提供VMware Workstation 17 Pro安装银河麒麟Kylin V10 SP3的详细教程,涵盖环境准备、虚拟机配置、系统安装及优化全流程。通过分步指导和实用技巧,帮助用户高效搭建国产操作系统开发测试环境,特别适合技术自主可控需求场景下的虚拟化实践。

weixin_30879169的博客 646

【Cadence】Virtuoso@LayoutXL 差分电路版图同步修改

对于差分电路,器件和部分走线通常是对称的,只需要画一半,另一半通过镜像操作完成。因此,需要对差分电路进行同步的修改,保证电路的差分对称性和正确的连接关系。然而,通常版图会经过多次修改,修改的部分可能在镜像的时候被遗漏。左边画了金属块,右边也出现了同步出现了金属块。进入group会有同步复制的提示。

乾巽的博客 3051

最全面的ConstraintLayout教程

亲自执笔,给大家带来新年第一篇原创文章

郭霖 5845

python编程实现制作网络流量监控动画

c,实时显示网络带宽使用情况,用柱状图或折线图表示不同时间段的流量变化。通过 Python编程实现图形库(如 Pygame、Tkinter、Matplotlib 等)来实现计算机网络基础概念的可视化动画。global bars # 声明 bars 为全局变量。# 获取当前网络流量。# 创建图形和坐标轴。

qq_42788199的博客 718

跟着大神学习ConstraintLayout

把Android studio 升级到3.1.3后,新建工程默认的布局已经变成了 android.support.constraint.ConstraintLayout。由于之前没用过ConstraintLayout,赶紧网上搜一波,觉得郭大神和鸿洋大神对ConstraintLayout解析的文章很有代表性,一个是可视化布局拖拽的学习,一个是通过xml手动添加属性。于是跟着大神们一起学习一下并记录...

u011799045的专栏 244

2024年中科大分子生物研究生考试建议

分子生物学复习资料及往年考题。

qq_43337249的博客 2956

【Arc GIS 零基础教学】土地利用类型图的绘制方法

​Hi,我是胡学长!今天教大家怎么利用Arc GIS 绘制土地利用类型图。土地利用类型图是表达土地资源的利用现状、地域差异和分类的专题地图。它是研究土地利用的重要工具和基础资料,同时也是土地利用调查研究的主要成果之一。在编制土地利用图的基础上,对当前利用的合理程度和存在的问题、进一步利用的潜力、合理利用的方向和途径,进行综合分析和评价。因此,土地利用图是调整土地利用结构,因地制宜进行农业、工矿业和交通布局、城镇建设、区域规划、国土整治、农业区划等的一项重要科学依据。......

一起来交流学习吧 1万+

ConstraintLayout学习

前言 在了解学习ConstraintLayout布局之前,开发中布局一个页面习惯LinearLayout和RelativeLayout一通嵌套完成布局。但是一个项目的优化中是包括布局优化的,多层的嵌套会影响到页面的绘制,性能开销也会很大。我们总不能自己创造出问题然后再去优化吧,加上升级as后创建一个Activity的默认根布局是ConstraintLayout,既然是官方推崇的,所以就去了解学习了下。在写这篇文章前已经在项目中尝试使用了ConstraintLayout,基本上每个页面都可以一个层级去布局出

weixin_37177125的博客 577

港口集装箱码头运营FlexSim仿真

列队4中的集装箱会根据不同类型的集装箱会放置在不同的堆场,因此根据前面对集装箱设置的标签Type的数值不同,设置不同的发送端口。集装箱到达列队3后,会有70%的集装箱到达堆场,30%的集装箱运出港口,因此在Queue列队3的Flow界面设置按照百分比发送端口,其中70%发送到端口1,即发送到列队4等待进入堆场,30%发送到端口2,即发送至出闸口。通过上述对比表格可以看出,当集卡数量在10的时候,岸桥和场桥的设备利用率达到了最高,当集卡数量为12的时候场桥1和场桥3的利用率有所下降,因此综合考虑。

m0_72514516的博客 1331

ConstraintLayout各个属性学习

一、概述 ConstraintLayout出现有一段时间了,不过一直没有特别去关注,也多多少少看了一些文字介绍,多数都是对使用可视化布局拖拽,个人对拖拽一直不看好,直到前段时间看到该文: 解析ConstraintLayout的性能优势 非常详尽的介绍了ConstraintLayout的性能优势,于是乎开始学习了一下ConstraintLayout。 本文的重点不在与可视化界面的学习,而在于如何...

永恒的齿轮的专栏 864

大地坐标系与经纬度转换(一):大地坐标系简介

一、大地坐标系 大地坐标系是大地测量中以参考椭球面为基准面建立起来的坐标系。地面点的位置用大地经度、大地纬度和大地高度表示。 二、地心坐标系 ...

qq_42895926的博客 6万+

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

ConstraintLayout学习总结

昨天更新了Android Studio,发现 现在xml的根布局已经默认是ConstraintLayout了,后知后觉的我去学习了一下官方文档,现在这里做个记录。 ConstraintLayout继承自ViewGroup,它允许你用一种灵活的方式去控制控件的位置及大小。 下面从一下七种约束来总结: Relative Position Relative Position是在约束布局中创建布局

WeirdoCy的博客 577

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ConstraintLayout的探究与学习

Google I/O 2016 上发布了 ConstraintLayout, 简直是要变革 Android 写界面方式. 于是第二天我立即找到相关文档尝试, 这是官方提供的 Codelab 项目. 手把手教你探索 ConstraintLayout. 英文原文: https://codelabs.developers.google.com/codelabs/constraint-layout

chanzhu的博客 1955

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Android ConstraintLayout学习

约束布局ConstraintLayout 是一个ViewGroup,可以在Api9以上的Android系统使用它,它的出现主要是为了解决布局嵌套过多的问题,以灵活的方式定位和调整小部件。从 Android Studio 2.3 起,官方的模板默认使用 ConstraintLayout。 作用:解决布局嵌套层次多,过度绘制,嵌套得越多,设备绘制视图所需的时间和计算功耗也就越多 引用库 depe...

HF1203的博客 474

Android学习笔记 64. ConstraintLayout使用布局编辑器

Android学习笔记 64. ConstraintLayout使用布局编辑器

代码改变世界 532

ConstraintLayout的学习

ConstraintLayout 翻译为 约束布局,也有人把它称作 增强型的相对布局,由 2016 年 Google I/O 推出。扁平式的布局方式,无任何嵌套,减少布局的层级,优化渲染性能。从支持力度而言,将成为主流布局样式,完全代替其他布局。但既然是增强型的相对布局 RelativeLayout中子控件常用属性: a、相对于父控件,例如:android:layout_alignParentTo...

weixin_43858561的博客 158

ConstraintLayout 学习笔记

如何阅读 xml 属性 与 Relativelayout 不同,ConstrainLayout 的属性需要同时说明需要怎么操作自己与目标控件,例如:layout_constraintLeft_toLeftOf 指自身左边缘与目标控件左边缘对齐 从此 match_parent 是故人 ConstraintLayout 里不再使用 match_parent,想要铺满屏幕,只能设置宽度为 0,...

donge5816的博客 250

ConstraintLayout布局学习

这两天跟着Google的官方文档学习了一下ConstraintLayout布局,相较于RelativeLayout来说最大的好处是ConstrainLayout布局可以减少嵌套,提升性能。 参考:解析ConstraintLayout的性能优势 https://mp.weixin.qq.com/s/gGR2itbY7hh9fo61SxaMQQ? 相对定位 ConstraintL...

diemei8613的博客 181

ConstraintLayout 学习记录

1、基本定位 layout_constraintLeft_toLeftOf layout_constraintLeft_toRightOf layout_constraintRight_toLeftOf layout_constraintRight_toRightOf layout_constraintTop_toTopOf layout_constraintTop_toBottomOf la...

fayangzhou的博客 388
上一篇: Java概述
下一篇: SQLite 数据库基础 —— (一)
cherry459
博客等级 码龄9年 4粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值