[英]Glide - Rounded Corner size different
我想在對話框中制作 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)
}
我試過 glide - overide、shapable imgae 等,但我做不到。 第一張圖片是12dp(換成像素)
您應該嘗試像這樣定義 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.