The purpose of the following function (in an Android app) is to programmatically lay out three vertical SeekBar objects one beside the other.
The setting for the constaints is a bit tricky, but the most difficult part for me here is to get the verticality of the bars. I use rotation = 270.0F, but the rotation is ignored as soon as I set constaints up. Can anybody tell me why this is happening?
fun setAdjustBars() {
val clrSetBarR = SeekBar(this)
val clrSetBarG = SeekBar(this)
val clrSetBarB = SeekBar(this)
clrSetBarR.thumbTintList = ColorStateList.valueOf(Color.rgb(255,0,0))
clrSetBarG.thumbTintList = ColorStateList.valueOf(Color.rgb(0,255,0))
clrSetBarB.thumbTintList = ColorStateList.valueOf(Color.rgb(0,0,255))
val sideColrVal = 77
clrSetBarR.progressTintList = ColorStateList.valueOf(Color.rgb(255,sideColrVal,sideColrVal))
clrSetBarG.progressTintList = ColorStateList.valueOf(Color.rgb(sideColrVal,255,sideColrVal))
clrSetBarB.progressTintList = ColorStateList.valueOf(Color.rgb(sideColrVal,sideColrVal,255))
val seekBarsArray = arrayOf(clrSetBarR,clrSetBarG,clrSetBarB)
seekBarsArray.map {
it.id = View.generateViewId()
it.rotation = 270.0F
constraintLayout?.addView(it)
constrSet.connect(it.id, ConstraintSet.TOP, deviceFrameID, ConstraintSet.TOP)
constrSet.connect(it.id, ConstraintSet.BOTTOM, deviceFrameID, ConstraintSet.BOTTOM)
constrSet.connect(it.id, ConstraintSet.LEFT, deviceFrameID, ConstraintSet.LEFT)
constrSet.connect(it.id, ConstraintSet.RIGHT, deviceFrameID, ConstraintSet.RIGHT)
}
val sideShift = 170
//constrSet.setMargin(clrSetBarR.id, ConstraintSet.RIGHT,sideShift)
//constrSet.setMargin(clrSetBarB.id, ConstraintSet.LEFT,sideShift)
constrSet.setMargin(clrSetBarG.id, ConstraintSet.LEFT,sideShift)
constrSet.setMargin(clrSetBarB.id, ConstraintSet.LEFT,sideShift*2)
/*
When using this code the 3 bars appears one after the other from top to bottom.*/
constrSet.setMargin(clrSetBarR.id, ConstraintSet.TOP,-sideShift)
constrSet.setMargin(clrSetBarB.id, ConstraintSet.BOTTOM,-sideShift)
// */
constrSet.applyTo(constraintLayout)
}