[英]How can I prevent the cursor from resizing in an EditText (MultiAutoCompleteTextView) after I add an imagespan using a SpannableStringBuilder?
[英]How can I get rid of unwanted space over ImageSpan that appears if I also add text to EditText?
似乎 EditText 的高度計算為文本的最小頂部和最大底部之間的差異。 字體度量中的方向是向下的,0 是文本的基線。
在左側截圖中,由DynamicDrawableSpan.getSize()
設置,底部為 0,頂部為 -250,即圖像高度。 這給了我們 250 的高度。
在右側的屏幕截圖中,附加文本將底部設置為 15。頂部仍為 -250。 高度變為 265 像素。 ImageSpan
仍然從底部繪制,所以你會得到這個奇怪的空間。
我不確定這是否是最佳解決方案,但這適用於我的用例:
class FullHeightImageSpan(
val context: Context,
val bitmap: Bitmap
) : ImageSpan(context, bitmap) {
override fun getSize(paint: Paint, text: CharSequence?,
start: Int, end: Int,
fm: Paint.FontMetricsInt?): Int {
val oldBottom = fm?.bottom
val result = super.getSize(paint, text, start, end, fm)
fm?.apply {
top += oldBottom!!
ascent = top
bottom = oldBottom
}
return result
}
}
在這里,我只是保留了文本的bottom
,而不是將其設置為 0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.