kotlin 滑动-圆角大小不同

tag5nh1u  于 2023-01-09  发布在  Kotlin
关注(0)|答案(1)|浏览(78)

我想在一个对话框4DP圆角图像。

但当我给4dp(改变为像素),imgae是这样做的。

底角是背景绘制。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="@android:color/white" />

    <corners
        android:bottomRightRadius="4dp" />

</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="@android:color/white" />

    <corners
        android:bottomLeftRadius="4dp" />

</shape>

我试过这个代码。请帮帮我😢😢

private fun initView() {
        val dm = ctx.resources.displayMetrics
        val width = dm.widthPixels - 60
        val radius = dpToPx(4).toFloat()

        window?.run {
            setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT)
            setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }

        Glide.with(ctx)
            .load(quizNoticeImage)
            .transform(GranularRoundedCorners(radius, radius, 0f, 0f))
            .listener(object : RequestListener<Drawable> {
                override fun onLoadFailed(
                    e: GlideException?,
                    model: Any?,
                    target: Target<Drawable>?,
                    isFirstResource: Boolean
                ): Boolean {
                    noShowAgain()
                    return false
                }

                override fun onResourceReady(
                    resource: Drawable?,
                    model: Any?,
                    target: Target<Drawable>?,
                    dataSource: DataSource?,
                    isFirstResource: Boolean
                ): Boolean {
                    vBarHorizontal.visible()
                    vBarVertical.visible()
                    tvNoShowAgain.visible()
                    tvClose.visible()
                    return false
                }
            })
            .into(ivQuiz)

        ivQuiz.setOnClickListener(this)
        tvNoShowAgain.setOnClickListener(this)
        tvClose.setOnClickListener(this)
    }

我试过滑动覆盖,可变形的图像等.但我不能使这个.第一个图像是12dp(改变为像素)

lmyy7pcs

lmyy7pcs1#

您应该尝试像这样定义alertDialog:

val alertDialog : AlertDialog =  MaterialAlertDialogBuilder(this, R.style.MyRounded_MaterialComponents_MaterialAlertDialog)  // for fragment you can use getActivity() instead of this

和这样的风格:

<style name="MyRounded.MaterialComponents.MaterialAlertDialog" 
    parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">

    <item name="shapeAppearanceOverlay">
        @style/ShapeAppearanceOverlay.App.CustomDialog.Rounded
    </item>
    <item name="colorSurface">
        @color/YOUR_COLOR
    </item>
</style>

<style name="ShapeAppearanceOverlay.App.CustomDialog.Rounded" parent="">
    <item name="cornerFamily">
        rounded
    </item>
    <item name="cornerSize">
        4dp
    </item>
</style>

相关问题