首页技术width constraint,attribute指令

width constraint,attribute指令

编程之家2026-06-29884次浏览

大家好,今天给各位分享width constraint的一些知识,其中也会对attribute指令进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!

width constraint,attribute指令

Android-ConstraintLayout约束布局使用

这里分别以:app:layout_constraintLeft_toLeftOf和app:layout_constraintRight_toLeftOf举例:

定义两个控件:

这里的id为where的TextView就使用了app:layout_constraintLeft_toLeftOf相对于另一个TextView,这个时候id为where的TextView的显示的位置,其实是左边贴在了id为right_top的TextView的左边上。如下图:

这个时候如果将id为where的相对于id为right_top的修改成app:layout_constraintRight_toLeftOf,如下所示:

那么此时显示的样式,就是id为where的TextView相对于id为right_top的TextView的右边显示。如下图:

这个属性,是让A和B两个控件的基准线在同一个水平位置上,比如两个TextView,大小不同,字体的大小也不同,那么想要让这样两个不同大小不同字体大小的文本内容显示在同一个基线,则可以使用该属性。app:layout_constraintBaseline_toBaselineOf

width constraint,attribute指令

在约束布局中,margin控制需要存在约束关系的才会生效,比如控件A某条边相对于控件B的某条边存在约束关系,则控件A与B之间的margin才会生效。

这里使用了两种margin属性,一种就是app:layout_goneMarginEnd,这个只在right_top被gone的时候生效;一种就是android:layout_marginEnd,任何时候都生效。

但是这里的margin需要生效,只有id为where的TextView被id为right_top的TextView所约束,那么id为where的TextView的margin相对于id为right_top的TextView的才生效。而id为right_top的TextView并没有被id为where的TextView约束,所以id为right_top的TextView的margin_start其实看不到生效。这里其实可以认为right_top的margin_start生效了,只不过是相对于parent的左边,但是因为right_top在parent的右上角,所以看不到这个margin效果

这两个属性单独使用并不能生效,水平方向的必须要给控件的左右两边都添加约束才会生效,垂直方向的必须要给控件的上下两边都添加约束才可以生效。

比如这个例子,Button的左边被TextView的右边约束,Button的右边被parent约束,这样Button的左右两边都有约束,那么给Button添加水平方向的bias属性就可以生效,即根据Button的左边约束偏移一定的比例,这里就是相对于TextView的右边位置偏移40%。

bias的偏移,是根据控件的水平或者垂直方向的剩余位置的百分比来偏移。

width constraint,attribute指令

如果是在ConstraintLayout中居中,则:

如果是在两个控件的中间,则可以:

设置宽高百分比,首先设置app:layout_constraintHeight_default="percent"采用百分比形式,其次使用app:layout_constraintHeight_percent="0.3"设置一个0-1的百分比值,最后控件的宽高需要设置为 0dp,只有宽高是设置为 0dp的,百分比才生效。

在约束布局中,给控件的左右两边或者上下两边添加约束之后,给控件的宽高设置为0dp的时候,可以占满两个约束控件中间所有剩余空间。

比如这个布局,我们需要EditText在TextView的右边,如果不给EditText设置0dp的宽度,而是设置了match_parent的话,则会占满屏幕宽度,没办法实现EditText在TextView的右边

在ConstraintLayout中给控件设置min的宽度和高度,必须是要控件的layout_width或者layout_height为wrap_content或者0dp时。给控件设置max的宽度或者高度的时候,必须是要控件的layout_width或者layout_height为0dp时。

不过在设置max的时候需要注意一点,如果单纯只是设置了0dp,如果没给控件添加对应的左右约束或者上下约束,比如没有设置左右约束,那么layout_constraintWidth_max设置的再大也不会超过整个控件的wrap_content的长度。

这里的绿色区域的控件,宽度显示的明显没有达到550dp,但是也不会继续变长了。

如果是设置了左右约束,那么最大宽度的限制也就是左右两个约束中间的剩余空间宽度

同时给Guide设置layout_constraintGuide_percent和layout_constraintGuide_begin的时候,layout_constraintGuide_begin并不会生效。

layout_constraintGuide_begin是给Guide设置相对于开始位置的偏移,layout_constraintGuide_end是给Guide设置相对于结束位置的偏移。

layout_constraintGuide_percent是设置Guide设置相对于起始位置的偏移百分比。

Guide的作用就是为了给控件的提供一个约束参考线,控件可以依靠这个线条约束。

app:constraint_referenced_ids这里是添加约束的控件的id,app:barrierDirection是添加约束的位置,可以有end、start、left、right、top、bottom

添加不同的值,就可以让Barrier线条在约束的控件的对应位置上,比如end,就是让Barrier线条在username1和password1这两个控件的右边结束位置

这两个都是线条,都是辅助约束的,但是这两个有一点区别,就是当控件比如出现切换手机语言,而造成控件上的文本显示长度出现变化的时候,Guideline并不会随着控件的长度变化而变化,这样就会造成约束不灵活,而Barrier可以根据控件的宽高变化,灵活移动位置。

所以控件宽高是随着内容动态变化的,建议使用Barrier,如果控件的内容是不变的,可以使用Guideline。

约束布局ConstraintLayout使用详解

从 Android Studio 2.3起,官方的模板默认使用 ConstraintLayout。 ConstraintLayout官方文档,之前项目中用的比较少,有些属性不是很熟练,做个笔记方便查找

注意点:

两个 TextView的高度不一致,但是又希望他们文本对齐,这个时候就可以使用 layout_constraintBaseline_toBaselineOf

我们只有设置了相应的约束margin才有效,如设置了 layout_constraintLeft_toLeftOf或者

layout_constraintLeft_toRightOf后 layout_marginLeft才会生效。

goneMargin主要用于约束的控件可见性被设置为 gone的时候,使用的 margin值是否有效,属性如下:

控件的尺寸可以通过四种不同方式指定:

当控件的高度或宽度为wrap_content时,可以使用下列属性来控制最大、最小的高度或宽度:

android:minWidth最小的宽度

android:minHeight最小的高度

android:maxWidth最大的宽度

android:maxHeight最大的高度

注意!当ConstraintLayout为1.1版本以下时,使用这些属性需要加上强制约束,如下所示:

app:constrainedWidth=”true”

app:constrainedHeight=”true”

官方不推荐在ConstraintLayout中使用 match_parent,可以设置 0dp(MATCH_CONSTRAINT)配合约束代替 match_parent

当宽或高至少有一个尺寸被设置为0dp时,可以通过属性 layout_constraintDimensionRatio设置宽高比

如果两个或以上控件通过下图的方式约束在一起,就可以认为是他们是一条链(图为横向的链,纵向同理)。

layout_constraintHorizontal_chainStyle默认为 spread,效果如图

另外两个取值 packed

spread_inside

Guildline是一条辅助线,帮助你完成布局但它不会显示在界面上。

Guildline的主要属性:

android:orientation:垂直 vertical,水平 horizontal

layout_constraintGuide_begin指定位置距离开始

layout_constraintGuide_end指定位置距离结束

layout_constraintGuide_percent距离顶部的百分比(orientation= horizontal时则为距离左边)

假设有3个控件ABC,C在AB的右边,但是AB的宽是不固定的,这个时候C无论约束在A的右边或者B的右边都不对。当出现这种情况可以用Barrier来解决。Barrier可以在多个控件的一侧建立一个屏障,如下所示:

效果如下

Group可以把多个控件归为一组,方便隐藏或显示一组控件,举个例子:

设置 group的 visibility为 invisible,则text1与text3均不可见。

Placeholder指的是占位符,可以定义一个位置,当给 Placeholder使用 setContentId()设置另一个控件的id,使这个控件移动到占位符的位置了

在Activity中设置

实现点击四个角的那一个按钮,那么该按钮就会显示在正中间

android studio约束布局 如何制作阵列

ConstraintLayout(约束布局),是2016年Google I/O最新推出的Android布局,目前还在完善阶段.从推出的力度而言,应该会成为主流布局样式.在最新版本的Android Studio中, ConstraintLayout已经成为默认布局.

概念

ConstraintLayout约束布局的含义:根据布局中的其他元素或视图,确定View在屏幕中的位置.包含三个重要信息,根据其他视图设置位置,根据父容器设置位置,根据基准线设置位置.

layout_constraint[本源]_[目标]="[目标ID]"

例如:

app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"

约束当前View的底部至目标View的底部,目标View是constraintLayout.表明,把当前View放置到constraintLayout(父容器)的底部,并且底部一致.

为了演示多个示例,使用复用的Activity页面.根据参数设置标题和布局Id.

publicclassLayoutDisplayActivityextendsAppCompatActivity{privatestaticfinalString TAG= LayoutDisplayActivity.class.getSimpleName();staticfinalString EXTRA_LAYOUT_ID= TAG+".layoutId";//布局ID@OverrideprotectedvoidonCreate(@NullableBundle savedInstanceState){super.onCreate(savedInstanceState);setTitle(getIntent().getStringExtra(Intent.EXTRA_TITLE));finalintlayoutId= getIntent().getIntExtra(EXTRA_LAYOUT_ID,0);setContentView(layoutId);//设置页面布局,复用布局}}

主页面使用ListView展示多个项,每项都是不同的布局.点击项发送不同的Intent,填充所要显示的页面.

publicclassMainActivityextendsAppCompatActivity{@OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ListView list=(ListView) findViewById(R.id.activity_main);ArrayAdapter<String> adapter=newArrayAdapter<>(this,android.R.layout.simple_list_item_1, LIST_ITEMS);list.setAdapter(adapter);list.setOnItemClickListener(newAdapterView.OnItemClickListener(){@OverridepublicvoidonItemClick(AdapterView<?> adapterView, View view,inti,longl){//复用显示布局Intent intent=newIntent(MainActivity.this, LayoutDisplayActivity.class);intent.putExtra(Intent.EXTRA_TITLE, LIST_ITEMS[i]);//标题intent.putExtra(LayoutDisplayActivity.EXTRA_LAYOUT_ID, LAYOUT_IDS[i]);//布局IdstartActivity(intent);}});}}

基础

ConstraintLayout布局最基本的使用方式,就是直接指定位置.取消按钮的底部对齐constraintLayout(父容器)的底部,左侧对齐父容器的左侧.下一步按钮的底部对齐父容器的底部,而左侧对齐取消按钮的右侧.并且每个按钮边缘有Margin空隙.

<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:app="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"android:id="@+id/constraintLayout"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/cancel_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="16dp"android:layout_marginStart="16dp"android:text="取消"app:layout_constraintBottom_toBottomOf="@id/constraintLayout"app:layout_constraintStart_toStartOf="@id/constraintLayout"/><Buttonandroid:id="@+id/next_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="16dp"android:layout_marginStart="16dp"android:text="下一步"app:layout_constraintBottom_toBottomOf="@id/constraintLayout"app:layout_constraintStart_toEndOf="@id/cancel_button"/></android.support.constraint.ConstraintLayout>

ConstraintLayout的属性设置,最重要的就是理解属性的表示含义.

Base

比例

ConstraintLayout布局除了对齐属性,还有重要的比例属性.中心(Center)按钮需要把全部边界与constraintLayout(父容器)边界对齐,则为居中.同时还可以设置水平与竖直的比例,如0.25.Bias按钮设置水平与竖直的比例是0.25,表示左侧与右侧比例是1:4,上部与下部的比例是1:4.

constraintHorizontal_bias设置水平比例,constraintVertical_bias设置竖直比例.

<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:app="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:tools="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"android:id="@+id/constraintLayout"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Center"app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"app:layout_constraintEnd_toEndOf="@id/constraintLayout"app:layout_constraintStart_toStartOf="@id/constraintLayout"app:layout_constraintTop_toTopOf="@+id/constraintLayout"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Bias"app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"app:layout_constraintEnd_toEndOf="@id/constraintLayout"app:layout_constraintHorizontal_bias="0.25"app:layout_constraintStart_toStartOf="@id/constraintLayout"app:layout_constraintTop_toTopOf="@+id/constraintLayout"app:layout_constraintVertical_bias="0.25"/></android.support.constraint.ConstraintLayout>

tools:layout_editor_absoluteX属性对于视图起到辅助作用,理解边界的真实距离,点击可视化布局会自动生成.

Bias

引导线

ConstraintLayout布局除了与布局对齐以外,还可以与引导线(Guideline)对齐.设置竖直引导线(Guideline)距离左侧72dp.按钮(Button)的左侧都与引导线对齐,上下使用比例的方式排列,一个0.25比例,一个0.75比例.

<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:app="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:tools="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"android:id="@+id/constraintLayout"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.constraint.Guidelineandroid:id="@+id/guideLine"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"app:layout_constraintGuide_begin="72dp"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Guide Up"app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"app:layout_constraintStart_toStartOf="@id/guideLine"app:layout_constraintTop_toTopOf="@+id/constraintLayout"app:layout_constraintVertical_bias="0.25"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Guide Down"app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"app:layout_constraintStart_toStartOf="@id/guideLine"app:layout_constraintTop_toTopOf="@+id/constraintLayout"app:layout_constraintVertical_bias="0.75"/></android.support.constraint.ConstraintLayout>

Guide Line

视图尺寸

ConstraintLayout布局中的控件也可以设置填充尺寸.控件把宽度设置为0dp会自动根据位置进行填充.如Large按钮,左侧对齐与Small按钮的左侧,右侧对齐与constraintLayout父控件的右侧,宽度设置为0dp,实际会填充全部位置.

<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:app="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"android:id="@+id/constraintLayout"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/small"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Small"app:layout_constraintStart_toStartOf="@id/constraintLayout"app:layout_constraintTop_toTopOf="@id/constraintLayout"/><Buttonandroid:layout_width="0dp"android:layout_height="wrap_content"android:text="Large"app:layout_constraintBottom_toBottomOf="@id/constraintLayout"app:layout_constraintEnd_toEndOf="@id/constraintLayout"app:layout_constraintStart_toEndOf="@id/small"app:layout_constraintTop_toTopOf="@id/constraintLayout"/></android.support.constraint.ConstraintLayout>

Measure

视图纵横比

ConstraintLayout布局还可以使用constraintDimensionRatio设置视图的纵横比,则需要把宽(layout_width)或者高(layout_height)设置为0dp,根据另一个属性和比例,计算当前属性,如两个图片控件的显示大小.

<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"xmlns:app="<a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="""="" style="text-decoration: none; border-radius: 0px; border: 0px; bottom: auto; float: none; height: auto; left: auto; margin: 0px; outline: 0px; overflow: visible; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto; box-sizing: content-box; font-size: 14px; min-height: inherit; color: rgb(92, 230, 56)!important; background: 0px 50%;">"android:id="@+id/constraintLayout"android:layout_width="match_parent"android:layout_height="match_parent"><ImageViewandroid:layout_width="0dp"android:layout_height="200dp"android:background="@color/colorAccent"android:src="@drawable/total_large"app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"app:layout_constraintRight_toRightOf="@+id/constraintLayout"app:layout_constraintTop_toTopOf="@+id/constraintLayout"app:layout_constraintVertical_bias="0.0"/><ImageViewandroid:layout_width="0dp"android:layout_height="200dp"android:background="@color/colorAccent"android:contentDescription="@null"android:src="@drawable/total_large"app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"app:layout_constraintDimensionRatio="4:3"app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"app:layout_constraintRight_toRightOf="@+id/constraintLayout"/></android.support.constraint.ConstraintLayout>

Ratio

ConstraintLayout约束布局的基本使用方式就是这些,可以观察到ConstraintLayout布局兼顾LinearLayout与RelativeLayout的优点,非常适合构建复杂布局,会成为Android的主流布局方式.

关于width constraint和attribute指令的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

web前端开发初级?前端开发if语句的用法 if函数怎么弄