校历第五周
[TOC]
TODO
- 激活新镜像的Nano——OK
- 做物联网作业(第五周的)
- 做 Java 高级作业(第五周的)—— OK
- 做 PB作业(第四周的)—— OK
- 微积分作业:上周的自评与互评+这周的作业——OK
- TFCC2车道偏离预警,新model的试用 —— OK
- 本地运行成功,已经保存为GIT和ZIP。ZIP在个人云。
- TinyML 文档ZIP 链接 需要 Alt 加 鼠标左键单击 —— OK
- 人工智能导论课,PPT —— 预备写讲稿
- 从旧书包里拿回硬盘 —— OK
Taps
IIC Scanner 用于判断 IIC总线 从设备是否在总线上
|


Guideline (辅助布局)
copy from https://www.twle.cn/
Guideline 只能用于 ConstraintLayout 中,是一个工具类,不会被显示,仅仅用于辅助布局
它可以是 horizontal 或者 vertical 的,例如 android:orientation="vertical"
vertical的Guideline宽度为零,高度为ConstraintLayout的高度horizontal的Guideline高度为零,宽度为ConstraintLayout的高度
定位Guideline有三种方式
- 指定距离左侧或顶部的固定距离 ( layout_constraintGuide_begin)
- 指定距离右侧或底部的固定距离 ( layout_constraintGuide_end)
- 指定在父控件中的宽度或高度的百分比 ( layout_constraintGuide_percent)
我们写一个 demo 演示下 Guideline
创建一个 空的 Android 项目
cn.twle.android.ConstraintLayout修改
activity_main.xml为以下内容<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="100dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Button"
app:layout_constraintLeft_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
运行范例,显示如下

Guideline 类源码
copy from https://www.twle.cn/
既然是一个辅助类,我倒是很好奇它的源码长的怎么样,哈哈
public class Guideline extends View { |
源码就这么一点点,而且大部分都是构造函数
查找下 8 是什么,可以发现如下定义
public static final int GONE = 0x00000008; |
- 也就是说,它默认是
GONE的 public void setVisibility(int visibility)被空实现了,所以没办法改变它的可见度this.setMeasuredDimension(0, 0);和public void draw(Canvas canvas)的空实现,表明这是一个超轻量的 View,不可见,没有宽高,也不绘制任何东西
所以,Guideline 只有一个作用,那就是 锚点