美文网首页
关于androidconstraintlayout的链式模式布局

关于androidconstraintlayout的链式模式布局

作者: 林下人水边兵 | 来源:发表于2019-11-19 15:48 被阅读0次

Chain 链模式一共有三种,分别为:spread ,spread_inside 和 packed 。

spread:将(横向或者垂直)空间 平均分给 所有的链式模式下的views( '链头控件'和'链尾控件' 两个是 不紧靠在父布局)

spread_inside: 将(横向或者垂直)空间 平均分给 所有的链式模式下的views( '链头控件'和'链尾控件' 两个是 紧靠在父布局)

packed :将 链式下的所有空间 紧挨在一起 居中

spread 和 spread_inside 两个 可以设置权重 和linearlayout 类似

代码demo

xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto">   android:id="@+id/tv1" android:layout_width="0dp" 
android:layout_height="wrap_content" 
app:layout_constraintHorizontal_weight="1" 
android:text="1"
 android:background="@color/cl_green"
 app:layout_constraintHorizontal_chainStyle="spread" 
app:layout_constraintStart_toStartOf="parent"
 app:layout_constraintEnd_toStartOf="@+id/tv2" />
 android:id="@+id/tv2" android:layout_width="0dp" 
app:layout_constraintHorizontal_weight="1" 
android:layout_height="wrap_content" 
android:text="1" android:background="@color/red" 
app:layout_constraintStart_toEndOf="@+id/tv1" 
app:layout_constraintEnd_toStartOf="@+id/tv3" /> 
android:id="@+id/tv3" 
app:layout_constraintEnd_toEndOf="parent" 
app:layout_constraintStart_toEndOf="@+id/tv2" 
android:layout_width="0dp"
 app:layout_constraintHorizontal_weight="1"
 android:layout_height="wrap_content" 
android:text="1" 
android:background="@color/cl_green" /> 
002vcGaKzy7nVGTywWx8d&690.jpg

spread 模式

xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto">  
 android:id="@+id/tv1" 
android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
android:text="1"
 android:background="@color/cl_green" 
app:layout_constraintHorizontal_chainStyle="spread"
 app:layout_constraintStart_toStartOf="parent" 
app:layout_constraintEnd_toStartOf="@+id/tv2" /> 
android:id="@+id/tv2"
 android:layout_width="wrap_content" 
android:layout_height="wrap_content"
 android:text="1"
 android:background="@color/red" app:layout_constraintStart_toEndOf="@+id/tv1" app:layout_constraintEnd_toStartOf="@+id/tv3" />
 android:id="@+id/tv3" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/tv2" 
android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
android:text="1" android:background="@color/cl_green" />

002vcGaKzy7nVHM6Vfmcc&690.jpg

spread_inside 模式

代码和 spread 一样 只是一个属性不同 <wbr> <wbr>

app:layout_constraintHorizontal_chainStyle="spread_inside"

002vcGaKzy7nVHNo2GB09&690.jpg

相关文章

网友评论

      本文标题:关于androidconstraintlayout的链式模式布局

      本文链接:https://www.haomeiwen.com/subject/vqtgictx.html