2

2 つのレイアウト タイトルと説明を含む xml を作成する必要があります。タイトルレイアウトでは、境界線を追加する必要があります。左下と右に半分の円があり、説明レイアウトの境界線には左上と右に円の半分があります。これが私のデザインです

ここに画像の説明を入力

長方形の半径の境界線の上に2つの半円を作成することでそれを行うことができますが、これを使用したくありません。どうすれば別のソリューションでそれを行うことができますか? それを行うための重要な作業または解決策を教えてください!どうもありがとう!

4

1 に答える 1

2

ShapeAppearanceModelカスタムの定義を使用しCornerTreatmentて、コンポーネントに適用できます。何かのようなもの:

    val radius = resources.getDimension(R.dimen.default_corner_radius)
    val title_layout = findViewById<LinearLayout>(R.id.title_layout)
    
    val titleShapeModel = ShapeAppearanceModel().toBuilder()
            .setTopLeftCorner(CornerFamily.ROUNDED, radius)
            .setTopRightCorner(CornerFamily.ROUNDED, radius)
            .setBottomLeftCorner(ConcaveRoundedCornerTreatment()).setBottomLeftCornerSize(radius)
            .setBottomRightCorner(ConcaveRoundedCornerTreatment()).setBottomRightCornerSize(radius)
            .build()
    val titleBackground = MaterialShapeDrawable(titleShapeModel)
    titleBackground.setStroke(1f, ContextCompat.getColor(this, R.color.colorPrimaryDark))

    ViewCompat.setBackground(title_layout, titleBackground)

は次のConcaveRoundedCornerTreatmentとおりです。

class ConcaveRoundedCornerTreatment : CornerTreatment() {

    override fun getCornerPath(
            shapePath: ShapePath,
            angle: Float,
            interpolation: Float,
            radius: Float
    ) {
        val interpolatedRadius = radius * interpolation
        shapePath.reset(0f, interpolatedRadius, ANGLE_LEFT, ANGLE_LEFT - angle)
        shapePath.addArc(
                -interpolatedRadius,
                -interpolatedRadius,
                interpolatedRadius,
                interpolatedRadius,
                ANGLE_BOTTOM,
                -angle
        )
    }

    companion object {
        const val ANGLE_LEFT = 180f
        const val ANGLE_BOTTOM = 90f
    }
}

説明レイアウトで同じことを行うだけです:

ここに画像の説明を入力

CardView組み込みの のようなビューを使用している場合shapeAppearanceModel:

cardView.shapeAppearanceModel = cardView.shapeAppearanceModel.toBuilder()
        .setTopRightCorner(concaveRoundedCornerTreatment).
        .........
        .build()
于 2020-07-15T05:25:24.843 に答える