ConstraintSet.createHorizontalChain方法

博主学习了 ConstraintLayout 1.1.2 版本的用法,发现部分功能已由官方更新,如 createHorizontalChain 方法参数变为 7 个。在学习中,代码设置 chain 时原方法不可用,经调试修改代码实现了效果,并说明了相关参数要求。

最近学习了大婶们的constraintLayout用法,

https://github.com/xitu/gold-miner/blob/master/TODO/constraint-layout-animations-dynamic-constraints-ui-java-hell.md

而此时版本已经是1.1.2

implementation 'com.android.support.constraint:constraint-layout:1.1.2'

发现有些功能已经官方更新了,比如createHorizontalChain方法

public void createHorizontalChain(int leftId, int leftSide, int rightId, int rightSide, int[] chainIds, float[] weights, int style) {
    this.createHorizontalChain(leftId, leftSide, rightId, rightSide, chainIds, weights, style, 1, 2);
}

参数已经是7个了,而在学习中发现代码设置chain已经没有这个方法,经过调试修改为以下代码,实现了效果

mApplyConstraintSet.createHorizontalChain(R.id.constraintLayout,ConstraintSet.LEFT,R.id.constraintLayout,ConstraintSet.RIGHT,new int[]{R.id.button1,R.id.button2,R.id.button3},null, ConstraintWidget.CHAIN_SPREAD);

leftId 基准的左边控件id,可以是guideLine

leftSide 须为ConstraintSet.LEFT或者ConstraintSet.RIGHT,其他参数运行出错

rightId 基准的右边控件id,可以是guideLine

rightSide 须为ConstraintSet.LEFT或者ConstraintSet.RIGHT,其他参数运行出错


 

1、编写一个在安卓下运行的5x5的乘法表。当点击左对齐按钮时乘法表左对齐,点击右对齐按钮时变成右对齐。左或右对齐时需要对齐屏幕的边缘。 2、每个TextView的背景色不相同。 3、每个TextView的宽度至少比文字宽度多出一个字符宽度。 4、第一列文字左对齐,第二列文字居中对齐,第三列文字右对齐,第四列等号对齐。 5、以上效果用两种方案来实现。 6、如果使用图片切换,图片中需要有姓名的水印。 7、标题栏中显示学号和姓名。 8、源码要求清晰、简洁,关键代码、类和方法有详尽注释,并在文档中列出。 9、Package名称为:com.姓名首字母缩写。 10、文档需配有与代码相符的功能模块图或流程图。 11、运行结果需截图,标题栏中显示学号的姓名。 12、电子版实验报告还需附java和布局xml代码。 13、实验心得不少于200字。 实现方法: 1、两张图片切换或隐藏(此方法需要在图片中添加自己名字的水印) 2、嵌套布局,对最外的布局对齐(静态和动态布局) 3、动态填充TextView 4、在两个布局文件间切换 5、TextView的setLayoutParams方法 6、Visible 7、TableLayout动态填空 8、TableLayout的android:collapseColumns="1"<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:padding="12dp" android:background="#F5F5F5" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 唯一标题 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="201-cfj 5×5 乘法表实验" android:textSize="20sp" android:gravity="center" android:background="#3F51B5" android:textColor="#FFFFFF" android:padding="10dp"/> <!-- 方案 A 控制栏 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="【方案A】图片+布局切换" android:textStyle="bold" android:layout_marginTop="10dp"/> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btn_a_left" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="向左"/> <Button android:id="@+id/btn_a_right" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="向右"/> </LinearLayout> <FrameLayout android:id="@+id/container_a" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp"/> <!-- 方案 B 控制栏 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="【方案B】TableLayout 动态填充" android:textStyle="bold"/> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btn_b_left" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="向左"/> <Button android:id="@+id/btn_b_right" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="向右"/> </LinearLayout> <TableLayout android:id="@+id/table_b" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
最新发布
10-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值