【问题标题】:How to draw a border to outside and inside of view?如何在视图的外部和内部绘制边框?
【发布时间】:2023-02-24 04:22:53
【问题描述】:

我想为 Column 绘制两个边框(1 个内部 - 1 个外部)。

预期结果:

Modifier.border(2.dp) // -> this creates inner border.

【问题讨论】:

    标签: android kotlin android-jetpack-compose android-jetpack


    【解决方案1】:

    您可以简单地应用 border 修饰符,然后应用 padding

    就像是:

        val shape = RoundedCornerShape(16.dp)
    
        Box(modifier = Modifier
            .size(60.dp , 100.dp)
            .border(2.dp, Blue, shape)
            .padding(4.dp)
            .background(Blue, shape)
        ){
          //content
        }
    

    如果您需要“内部”边框的颜色:

        Column(modifier = Modifier
            .size(60.dp)
            .border(2.dp, Blue, shape)
            .background( Teal200 , shape) 
            .padding(4.dp)
            .background(Blue, shape)
        )
    

    【讨论】:

    • 感谢您的好解决方案,但结果中白色部分的角并不是我想要的。角的半径与我预期的结果不一样。
    【解决方案2】:

    enter image description here

    @可组合 有趣的边框框(){

    val shape = RoundedCornerShape(4.dp)
    Box(
        modifier = Modifier
            .size(120.dp)
            .border(3.dp, Blue, shape)
            .padding(4.dp)
            .background(Blue, shape)
    ) {
    
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 2023-04-03
      • 2023-03-22
      • 2021-04-15
      • 2013-02-02
      • 1970-01-01
      相关资源
      最近更新 更多