android compose ConstraintLayout

implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
@Preview
@Composable
fun Greeting() {
    ConstraintLayout(Modifier.fillMaxSize(1f)) {
        val (text1,text2)=createRefs()
        val guideLine = createGuidelineFromStart(0f)    // 左
        val guideLine2 = createGuidelineFromEnd(0.9f)   // 右
        Text(text = "text1",  Modifier.constrainAs(text1){
            top.linkTo(parent.top)
            bottom.linkTo(parent.bottom)
            start.linkTo(parent.start)
            end.linkTo(parent.end)
        }.background(color = Color.Black), color = Color.White)
        Text(text = "test2",  Modifier.constrainAs(text2){
            top.linkTo(text1.top)
            bottom.linkTo(text1.bottom)
            start.linkTo(text1.start)
            end.linkTo(parent.end)
            linkTo(start = guideLine,end = guideLine2)
        }.background(color = Color.Blue), color = Color.Red)
    }
}

createGuidelineFromStart或者其他的指导线来替代layout_constraintVertical_bias或者layout_constraintHorizontal_bias

你可能感兴趣的:(android基础,android,vue.js,elementui)