[英]Want to increase the size of unicode surrogate pair symbol, e.g., the mathematical i symbol, within a string
I am programming in Kotlin in Android Studio 3.1.4. 我正在Android Studio 3.1.4中的Kotlin中编程。 I have strings that contain the mathematical i symbol.
我有包含数学i符号的字符串。 I want to increase the size of the symbol only, not the rest of the text in the string.
我只想增加符号的大小,而不要增加字符串中其余文本的大小。 The mathematical i requires a unicode surrogate pair, which I just recently learned how to display.
数学上,我需要一个unicode代理对,我最近才学会了如何显示。 I fear that this makes things a little more complicated than just having two separate fonts in a single string.
我担心这会使事情变得比仅在单个字符串中包含两个单独的字体要复杂得多。 The entire string is displayed in a viewText widget.
整个字符串显示在viewText小部件中。
Note: I am experimenting using a SpannableString with a RelativeSizeSpan as suggested in the answer below. 注意:我正在尝试将SpannableString与RelativeSizeSpan结合使用,如下面的答案所示。 I hope to learn how this applies to unicode surrogate pairs.
我希望了解这如何适用于unicode代理对。 Thank you.
谢谢。
You can use a SpannableString with a RelativeSizeSpan to resize just the infinity symbol. 您可以将SpannableString与RelativeSizeSpan一起使用以仅调整无穷大符号的大小。
For example we can resize the & symbol like this: 例如,我们可以这样调整&符号的大小:
var styledString = SpannableString("Hello & welcome")
// 6 and 7 are the start and end index of the & sign
styledString.setSpan(new RelativeSizeSpan(2f), 6, 7, 0)
textView.setText(styledString)
I found this to be a good resource that helped me understand Spannable Strings. 我发现这是一个很好的资源,可以帮助我理解Spannable Strings。
I needed to enlarge the mathematical script i in various locations in a string, ie, not always at the same position in the string. 我需要在字符串中的各个位置放大数学脚本i,即不总是在字符串中的相同位置。 So, here's the code that worked:
因此,这是有效的代码:
numerator = "Surrogate pair test: "
var len: Int = numerator.length
val iScript: String = "\uD835\uDCBE"
numerator = numerator + iScript + iScript + " End of test."
var styledString = SpannableString(numerator)
var sizeI: Float = 4.0f
styledString.setSpan(RelativeSizeSpan(sizeI), len, len+2, 0)
txtV_Numerator3.setText(styledString)
Notice that I put two surrogate pairs in succession in the String "numerator" for purposes of the test. 请注意,出于测试目的,我在字符串“分子”中连续放置了两个代理对。 I needed "len+2" in the setSpan construct in order to print the first surrogate pair 4 times normal size.
我需要在setSpan构造中使用“ len + 2”,以便将第一个代理对打印为正常大小的4倍。 Not surprisingly, using "len+4" in the setSpan construct printed both surrogate pairs 4 times normal size.
毫不奇怪,在setSpan构造中使用“ len + 4”将两个替代对都打印为正常大小的4倍。 Using "len+1" or "len+3" provided ugly results with large question marks.
使用“ len + 1”或“ len + 3”会产生难看的结果,并带有较大的问号。
I also noticed that changing the size (ielargeness) of the surrogate pair changed the vertical spacing in my user interface. 我还注意到,更改代理对的大小(即大)会更改用户界面中的垂直间距。 That is, the change in size also changed the vertical spacing between the textView widgets of my activity.
也就是说,大小的变化也改变了我活动的textView小部件之间的垂直间距。 Accounting for that will require additional programming.
为此,将需要进行其他编程。
Conclusion: You can use the above answer to generate a different size surrogate pair as long as you allow for each surrogate pair to be 2 characters in length, and as long as you don't mind changing the vertical spacing in your user interface. 结论:只要允许每个代理对的长度为2个字符,并且只要您不介意更改用户界面的垂直间距,就可以使用上述答案生成不同大小的代理对。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.