复杂的是,如果我在setText中明确设置换行符,那么有时它会插入一个换行符,我没想到换行符,即:
"My first line of text\nMy Second line of text"Might get turned into (it's right adjusted in this version):"My first line of text My second line of text"
我不知道如何保持TextVIEw试图插入换行符,或者让它只是照顾格式化整个事情.如果我将一些文本设置为一个真正长的单词,它会在某个选定的位置插入一个换行符.而其他时候,我只是随机得到最后几行文字.
我应该明确地将字体大小设置得很小,以便正确布局,然后手动调整大小?有没有一个“最佳实践”,我应该用这个?如果我将字体大小设置为相当大的字体,那么它的作品是很好的,但是找出这样做的“正确”方式是很好的.而且我宁可不必手动添加4行单行TextVIEw并自己格式化.
我使用的布局xml是:
<TextVIEw androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" androID:layout_alignParentRight="true" androID:layout_margintop="10dip" androID:layout_marginRight="8dip" androID:singleline="false" androID:ellipsize="marque" androID:gravity="right|bottom" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:textSize="30sp"/>解决方法 您可以计算字符串长度,并将文本大小设置为适合每个长度的最佳大小
这种形式的东西
if(myString.length()==40){ myTextvIEw.setTextSize(11);else if(myString.length()==25){ myTextvIEw.setTextSize(16);...
我希望这有帮助.
总结以上是内存溢出为你收集整理的调整Android多行TextView的大小全部内容,希望文章能够帮你解决调整Android多行TextView的大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)