简体   繁体   English

要增加字符串中的unicode代理对符号(例如数学i符号)的大小

[英]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. 您可以将SpannableStringRelativeSizeSpan一起使用以调整无穷大符号的大小。

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.

相关问题 增加TextView的值,例如0作为点击值+1 - Increase value of TextView e.g. 0 as clicked value +1 如何检查 Cloud Firestore 中任何文档的集合中是否存在值(例如名称)? - How can I check if a value e.g. name exists in a collection within any of documents in Cloud Firestore? uniqueUntilChanged无法正常工作(例如,不同的列表大小不视为不同) - distinctUntilChanged not working (e.g. different list size is not considered different) 在Android上将listview重新排列为两列(例如,字符串列表) - Rearrange listview into two columns on Android (e.g. string list) 传递数组的ArrayList(例如ArrayList <String[]> 到意图 - Pass ArrayList of Arrays (e.g. ArrayList<String[]>) to Intent 如何计算出现在Android类中的每种变量类型的数量? 例如int,string等 - How can I count the number each variable type, appears in an Android class? e.g. int, string etc libGDX:共享按钮,用于在例如 Facebook、电子邮件、WhatsApp、Twitter 中共享一个简单的字符串 - libGDX: Share-button to share a simple String in e.g. Facebook, E-Mail, WhatsApp, Twitter 在自定义ListView中的项目(例如TextViews,Images,Buttons)上添加itemClickListener - adding itemClickListener on items e.g.(TextViews, Images, Buttons) within in a customized ListView 仅获取一个字符的货币符号(例如 $、₹ 等)(区域无关紧要) android kotlin - Get Currency symbol of only one character (e.g $,₹, etc) (Locale doesn't matter) android kotlin 属性值中“ android:”前缀的含义(例如“ android:imageButtonStyle”) - Meaning of 'android:' prefix within attribute value (e.g. “android:imageButtonStyle”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM