【问题标题】:Setting the ShapeAppearanceOverlay programmatically?以编程方式设置 ShapeAppearanceOverlay?
【发布时间】:2021-08-25 07:23:32
【问题描述】:

我将 Material.io 用于 ShapeableImageView。现在我想以编程方式设置 shapeAppearanceOverlay。在 XML 中它看起来像这样:

app:shapeAppearanceOverlay="@style/roundedImageView"

我找不到设置 shapeAppearanceOverlay 的函数。你知道我该如何设置吗?

提前谢谢你。

【问题讨论】:

    标签: android xml shapes


    【解决方案1】:

    您可以使用ShapeAppearanceOverlay::setShapeAppearanceModel 做到这一点,如下所示:

    val radius = resources.getDimension(R.dimen.some_corner_radius)
    val shapeAppearanceModel = imageView.shapeAppearanceModel.toBuilder()
        .setAllCornerSizes(radius)
        .build()
    circleShapeImageView.imageView = shapeAppearanceModel
    

    查看ShapeableImageViewShapeAppearanceModel 文档。

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 2018-11-26
      • 2011-04-18
      • 2012-07-18
      • 2016-02-15
      • 2014-07-26
      • 1970-01-01
      • 2011-06-06
      • 2012-02-12
      相关资源
      最近更新 更多