Skip to content
Yoshida Seisuke edited this page Jan 10, 2018 · 4 revisions

Center in parent

constraintLayout {
    backgroundColor = Color.YELLOW

    val button1 = button {
        id = View.generateViewId()
        text = "1"
    }

    constraints({
        parent - button1 - parent
    }, {
        parent - button1 - parent
    })
}

Center in parent

With margin

constraintLayout {
    backgroundColor = Color.YELLOW

    val button1 = button {
        id = View.generateViewId()
        text = "1"
    }.lparams(width = matchConstraint)

    constraints({
        parent - dip(50) % button1 % dip(50) - parent
    }, {
        parent - dip(100) % button1
    })
}

With margin

Packed chain and align with bottom

constraintLayout {
    backgroundColor = Color.CYAN

    val button1 = button {
        id = View.generateViewId()
        text = "1"
    }
    val button2 = button {
        id = View.generateViewId()
        text = "2"
    }
    val button3 = button {
        id = View.generateViewId()
        text = "3"
    }
    constraints({
        parent - chainPacked(button1, button2, button3).alignTail() - parent
    }, {
        parent - button1 - parent
    })
}

example3

Clone this wiki locally