当前位置:   article > 正文

【转载】约束布局ConstraintLayout_layout_constrainttop_totopof

layout_constrainttop_totopof

参考文章1:约束布局ConstraintLayout看这一篇就够了
参考文章2:学习Placeholder的使用

补充点

1. 文章1中的“3.3 角度定位”

使用角定位时,app:layout_constraintCircleRadius指的是两个控件的中心点的距离

2. 位置偏移说明

margin配置,如android:layout_marginLeft优先级高于app:layout_constraintLeft_toLeftOf="parent"、app:layout_constraintRight_toRightOf="parent"配置,高于layout_constraintHorizontal_bias配置

3. 文章1中的“3.7 链”

配置layout_constraintHorizontal_weight之后,layout_constraintHorizontal_chainStyle无效

4. 文章1中的“4.3 Group”

Groupapp:constraint_referenced_ids引用其他Groupid无效

补充学习代码xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text="TextView1"
        android:gravity="center"
        android:id="@+id/tv1"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:background="@android:color/holo_red_dark"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView2"
        android:id="@+id/tv2"
        app:layout_constraintCircle="@id/tv1"
        app:layout_constraintCircleAngle="120"
        app:layout_constraintCircleRadius="80dp"
        android:background="@android:color/holo_blue_dark"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView3"
        android:id="@+id/tv3"
        app:layout_goneMarginLeft="100dp"
        app:layout_constraintLeft_toRightOf="@id/tv1"
        app:layout_constraintTop_toTopOf="@id/tv1"
        app:layout_constraintBaseline_toBaselineOf="@id/tv1"
        android:background="@android:color/holo_green_dark"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="TextView4"
        android:id="@+id/tv4"
        android:layout_marginTop="50dp"
        app:layout_constraintDimensionRatio="4:2"
        app:layout_constraintTop_toBottomOf="@+id/tv3"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.1"
        android:layout_marginLeft="100dp"
        android:background="@android:color/holo_orange_dark"/>

    <TextView
        android:layout_marginTop="20dp"
        app:layout_constraintTop_toBottomOf="@+id/tv4"
        android:background="@android:color/holo_blue_light"
        android:id="@+id/tv5"
        android:text="TextView5"
        android:layout_width="0dp"
        app:layout_constraintHorizontal_weight="1"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_chainStyle="spread"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/tv6"/>

    <TextView
        app:layout_constraintTop_toTopOf="@+id/tv5"
        android:background="@android:color/holo_blue_dark"
        android:id="@+id/tv6"
        android:text="TextView6"
        android:layout_width="0dp"
        app:layout_constraintHorizontal_weight="2"
        android:layout_height="50dp"
        app:layout_constraintLeft_toRightOf="@+id/tv5"
        app:layout_constraintRight_toLeftOf="@+id/tv7"/>

    <TextView
        app:layout_constraintTop_toTopOf="@+id/tv5"
        android:background="@android:color/holo_blue_bright"
        android:id="@+id/tv7"
        android:text="TextView7"
        android:layout_width="0dp"
        app:layout_constraintHorizontal_weight="3"
        android:layout_height="60dp"
        app:layout_constraintLeft_toRightOf="@+id/tv6"
        app:layout_constraintRight_toLeftOf="@id/tv8" />

    <TextView
        app:layout_constraintTop_toTopOf="@+id/tv5"
        android:background="@android:color/holo_blue_light"
        android:id="@+id/tv8"
        android:text="TextView8"
        android:layout_width="0dp"
        app:layout_constraintHorizontal_weight="4"
        android:layout_height="70dp"
        app:layout_constraintLeft_toRightOf="@+id/tv7"
        app:layout_constraintRight_toRightOf="parent"/>

    <android.support.constraint.Barrier
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/barrier"
        app:barrierDirection="bottom"
        app:constraint_referenced_ids="tv5,tv6,tv7,tv8"/>

    <TextView
        app:layout_constraintTop_toBottomOf="@id/barrier"
        android:id="@+id/tv9"
        android:text="TextView9"
        android:layout_marginTop="20dp"
        android:background="@android:color/holo_orange_dark"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <android.support.constraint.Group
        android:id="@+id/group1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"
        app:constraint_referenced_ids="tv5,tv6,tv7,tv8"/>

    <android.support.constraint.Group
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/group2"
        android:visibility="visible"
        app:constraint_referenced_ids="group1,tv9"/>

    <android.support.constraint.Placeholder
        android:layout_marginTop="20dp"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/placeholder"
        app:layout_constraintTop_toBottomOf="@+id/tv9"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <android.support.constraint.Guideline
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/guideline1"
        app:layout_constraintGuide_percent="0.5"/>

    <android.support.constraint.Guideline
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/guideline2"
        app:layout_constraintGuide_percent="0.5"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView10"
        app:layout_constraintTop_toTopOf="@id/guideline1"
        app:layout_constraintBottom_toBottomOf="@id/guideline1"
        app:layout_constraintLeft_toLeftOf="@id/guideline2"
        app:layout_constraintRight_toRightOf="@id/guideline2"
        android:background="@android:color/holo_green_light"/>

</android.support.constraint.ConstraintLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168

运行截图
运行截图

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/225668
推荐阅读
相关标签
  

闽ICP备14008679号