Android-ConstraintLayout使用笔记(二)
2017-05-08 21:06
232 查看
上一节说到一些常用的约束,以及一些功能按钮的使用,接下来将记录ConstraintLayout布局中的一些其他属性:
1. 倾向:当一个控件在父控件位置处于居中位置时,我们可以设置:app:layout_constraintHorizontal_bias将其或左或右的倾向(垂直居中情况:app:layout_constraintVertical_bias上下倾向)
- 水平倾向:
- 垂直倾向:
2. 宽高比:在约束布局中出了一个app:layout_constraintDimensionRatio属性,用来约束宽高的比例,默认是:宽比高。此属性起作用的前提条件是,至少有一方(宽或者高)设置为0dp,并与其它控件产生相应的约束
当为宽高比例指定W或H关键字时:
goneMargin属性:A,B,C三个控件,依次水平排列,C对B控件设置为goneMarginLeft=”20dp”时,若B为visiable时,BC控件紧密挨着,若B为gone时,C距离A为20dp。B为invisible时,与visiable时位置一样。
上一节补充:
所谓基线就是一条看不见的线,是使开发者便于添加约束的线。可以添加水平基线和垂直基线两种
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时位置一样。
上一节补充:
基线的使用:
所谓基线就是一条看不见的线,是使开发者便于添加约束的线。可以添加水平基线和垂直基线两种
相关文章推荐
- Android-ConstraintLayout使用笔记
- android ConstraintLayout初次使用笔记
- 了解使用Android ConstraintLayout
- android 开发零起步学习笔记(十五):android: 静态XML和动态加载XML混合使用,以及重写Layout控件
- Android笔记--LayoutInflator源码和使用分析
- Android 减少布局层次—— ConstraintLayout 约束布局 的使用
- 了解使用Android ConstraintLayout
- [学习笔记]用户界面优化之Android侧滑菜单(DrawerLayout使用)
- Android进阶——实战使用ConstraintLayout 替代LinearLayout、RelativeLayout和PercentLayout
- Android ConstraintLayout详解-使用可视化的方式来编写界面
- android 布局之ConstraintLayout的使用
- Android N 分屏(多窗口支持)+ConstraintLayout简单使用
- Android ConstraintLayout使用指南
- Android ConstraintLayout 个人使用感受
- Android ConstraintLayout 使用详解
- Android笔记之使用LayoutInflater创建View
- Android ConstraintLayout布局的使用
- Android ConstraintLayout使用指南
- Android新布局ConstraintLayout的使用
- Android ConstraintLayout的基本使用