您的位置:首页 > 移动开发 > Android开发

Android-ConstraintLayout使用笔记(二)

2017-05-08 21:06 232 查看
上一节说到一些常用的约束,以及一些功能按钮的使用,接下来将记录ConstraintLayout布局中的一些其他属性:

1. 倾向:当一个控件在父控件位置处于居中位置时,我们可以设置:app:layout_constraintHorizontal_bias将其或左或右的倾向(垂直居中情况:app:layout_constraintVertical_bias上下倾向)

- 水平倾向:

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.3"/>




- 垂直倾向:

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.3"/>




2. 宽高比:在约束布局中出了一个app:layout_constraintDimensionRatio属性,用来约束宽高的比例,默认是:宽比高。此属性起作用的前提条件是,至少有一方(宽或者高)设置为0dp,并与其它控件产生相应的约束

<--不起作用情况,因为宽或高没有设置为0dp-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="@string/app_name"
app:layout_constraintDimensionRatio="1:3"/>

<-- 宽比高:1:3 -->
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="@string/app_name"
app:layout_constraintDimensionRatio="1:3"/>


当为宽高比例指定W或H关键字时:

// 宽比高,1:3
app:layout_constraintDimensionRatio="W,1:3"

// 高比宽,1:3
app:layout_constraintDimensionRatio="H,1:3"


goneMargin属性:A,B,C三个控件,依次水平排列,C对B控件设置为goneMarginLeft=”20dp”时,若B为visiable时,BC控件紧密挨着,若B为gone时,C距离A为20dp。B为invisible时,与visiable时位置一样。


上一节补充:

基线的使用:


所谓基线就是一条看不见的线,是使开发者便于添加约束的线。可以添加水平基线和垂直基线两种
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  布局