简体   繁体   English

使用SpannableStringBuilder添加图像跨度后,如何防止光标在EditText(MultiAutoCompleteTextView)中调整大小?

[英]How can I prevent the cursor from resizing in an EditText (MultiAutoCompleteTextView) after I add an imagespan using a SpannableStringBuilder?

Here is what it looks like in the beginning when I haven't added any imagespan chips - 这是开始时我没有添加任何图像跨度芯片的样子-

在此处输入图片说明

As you can tell there the cursor is placed at the right size and the gravity is respected. 如您所知,将光标放置在正确的大小,并且尊重重力。

Then when I add an imagespan, the cursor all of a sudden becomes bigger like this - 然后,当我添加一个图像跨度时,光标突然变大了,像这样-

在此处输入图片说明

I don't understand why this happens and I also don't know how to fix it, ie keep the cursor the same size. 我不明白为什么会这样,而且我也不知道如何解决它,即保持光标大小不变。

Finally when I start typing again, the cursor is all wierd while maintaining the size of the of the font and the span also moves a little to the bottom. 最终,当我再次开始键入时,在保持字体大小的同时,光标全都变了,跨度也稍微移到了底部。 I really want to the keep the cursor the same size and keep it centered 我真的想保持光标大小不变并保持居中

在此处输入图片说明

I'm aware of textCursorDrawable sizing using padding. 我知道使用padding的textCursorDrawable大小。 There are two potential problems with that - 1. Its API 12+ (We support 9 and above), this isnt a big deal though 2. I couldnt find a way to reset it programmatically, only saw access to it in the xml definition. 这样做有两个潜在的问题-1.它的API 12+(我们支持9及更高版本),尽管这没什么大不了的。2.我无法找到以编程方式重置它的方法,只能在xml定义中看到对其的访问。

Any ideas? 有任何想法吗?

Chances are the ImageSpan changes the lineheight after it's added. 添加后,ImageSpan可能会更改lineheight。 If you set a line height bigger than the imagespan, I have a feeling your cursor will remain constant size (but still large). 如果您将线高设置为大于图像跨度,那么我感觉您的光标将保持恒定大小(但仍然很大)。 At this point you can add padding to shrink it down to the smaller size you want and it should remain constant. 此时,您可以添加填充以将其缩小到所需的较小尺寸,并且应保持不变。

(I don't have a chance to test what I just wrote, so it's just a theory) (我没有机会测试我刚刚写的内容,所以这只是一个理论)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我还向 EditText 添加文本,如何消除出现的 ImageSpan 上不需要的空间? - How can I get rid of unwanted space over ImageSpan that appears if I also add text to EditText? 使用SpannableStringBuilder和ImageSpan的EditText不能正常工作 - EditText with SpannableStringBuilder and ImageSpan doesn't works fine 如何在TokenAutoComplete中的android中的multiautocompletetextview中从下拉列表中删除分隔线 - How can I remove divider from dropdown in multiautocompletetextview in android in TokenAutoComplete 如何从EditText中删除光标气泡的白色背景 - How can I remove the white background of cursor bubble from EditText 如何在for循环中使用SpannableStringBuilder? - how can I use SpannableStringBuilder in for loop? 如何将联系人光标数据绑定到带有芯片的MultiAutoCompleteTextView - How do I bind contact cursor data to a MultiAutoCompleteTextView with chips 当用户键入时,如何防止 EditText 调整自身大小? - How do I prevent an EditText from resizing itself when the user is typing? 单击时如何防止光标将其自身放置在EditText的开头 - How do I prevent cursor from placing itself at the beginning of EditText when clicked 如何防止 ImageView 以编程方式调整大小以适应屏幕? - How can I prevent an ImageView from resizing to fit the screen programmatically? 如何在 Kotlin 的 EditText 中的 4 个字符后添加空格? - How can I add space after 4 character in EditText at Kotlin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM