gpt4 book ai didi

android - 如何在android中创建s曲线布局

转载 作者:行者123 更新时间:2023-12-05 00:09:53 25 4
gpt4 key购买 nike

如何像附加图像一样创建布局或 View ,可用于 ImageView、Slider 等的形状。

最佳答案

你可以使用类似的东西。

    <FrameLayout
android:clipChildren="false"
android:clipToPadding="false"
...>

<ImageView/>

<com.google.android.material.card.MaterialCardView
android:id="@+id/card"
android:layout_marginTop="xxdp"
app:cardCornerRadius="48dp"
app:cardBackgroundColor="@color/colorSecondaryLight"
.../>

</FrameLayout>

然后应用一个ShapeAppearanceModel:

    val cardView = findViewById<MaterialCardView>(R.id.card)

cardView.shapeAppearanceModel = cardView.shapeAppearanceModel.toBuilder()
.setTopLeftCorner(CustomCornerTreatment())
.setBottomLeftCorner(CornerFamily.ROUNDED, 0f)
.setBottomRightCorner(CornerFamily.ROUNDED, 0f)
.build()

像这样的自定义 CornerTreatment:

class CustomCornerTreatment : CornerTreatment() {

override fun getCornerPath(
shapePath: ShapePath,
angle: Float,
interpolation: Float,
radius: Float
) {

val interpolatedRadius = radius * interpolation
shapePath.reset(0f, -radius * interpolation, 270f,270 -angle)
shapePath.addArc(
0f,
-2*interpolatedRadius,
2*interpolatedRadius,
0f,
180f,
- angle)

}
}

enter image description here

关于android - 如何在android中创建s曲线布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64219451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com