您可以通过设置徽章Drawable的边界来解决这个问题,以确保它不会被剪切。以下是一个例子,演示了如何使用边界来正确显示徽章Drawable:
val badge: Drawable = resources.getDrawable(R.drawable.badge, null) // 徽章Drawable
// 根据您的需要更改徽章Drawable的边界
badge.setBounds(0, 0, badge.intrinsicWidth, badge.intrinsicHeight)
// 在单个TextView上设置徽章Drawable
val textView: TextView = findViewById(R.id.textView)
val compoundDrawable: Array = textView.compoundDrawables
textView.setCompoundDrawables(null, compoundDrawable[1], badge, null)
这将在TextView的右侧设置徽章Drawable,并将其正确显示,而不被剪切。请注意,您需要根据需要更改徽章Drawable的边界,因为每个Drawable都有不同的尺寸和比例。