2020-05-18 ConstraintLayout代码设置属

2020-05-18  本文已影响0人  兣甅

1.需要clone进行设置

2.操作完成后需要applyTo生效

3.官网链接

val cons:ConstraintLayout
val big:Boolean
ConstraintSet().also {
  it.clone(cons)
  it.setHorizontalBias(R.id.childId, if (big) 0.6f else 0.5f)
}.applyTo(cons)
      ConstraintSet().also { cs ->
        cs.clone(music_song_container)
        //歌曲名称布局设置
        //android:id="@+id/music_song_name"
        //app:layout_constrainedWidth="true"
        //app:layout_constraintEnd_toStartOf="@id/music_singer_name"
        //app:layout_constraintHorizontal_bias="0"
        //app:layout_constraintHorizontal_chainStyle="packed"
        //app:layout_constraintStart_toStartOf="parent"
        cs.constrainedWidth(R.id.music_song_name, true)
        cs.connect(R.id.music_song_name, ConstraintSet.END, R.id.music_singer_name, ConstraintSet.START)
        cs.setHorizontalBias(R.id.music_song_name, 0f)
        cs.setHorizontalChainStyle(R.id.music_song_name, ConstraintSet.CHAIN_PACKED)
        cs.connect(R.id.music_song_name, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START)
        //歌手名称布局设置
        //android:id="@+id/music_singer_name"
        //app:layout_constraintEnd_toEndOf="parent"
        //app:layout_constraintStart_toEndOf="@id/music_song_name"
        cs.connect(R.id.music_singer_name, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END)
        cs.connect(R.id.music_singer_name, ConstraintSet.START, R.id.music_song_name, ConstraintSet.END)
      }.applyTo(music_song_container)
上一篇 下一篇

猜你喜欢

热点阅读