android–TextView文本对齐太可怕了!如何解决它?

android–TextView文本对齐太可怕了!如何解决它?,第1张

概述我似乎总是在布局上对齐文本时遇到的最大问题.好像TextView没有正确测量其文本.报告的TextView宽度和高度比实际文本大很多.人们可以期望TextView的宽度和高度紧紧地包裹在文本周围.下图显示了数字18和文本“SEC”未在同一底部基线上对齐的情况.这是因为较大的文本高度比文本大很

我似乎总是在布局上对齐文本时遇到的最大问题.好像TextVIEw没有正确测量其文本.报告的TextVIEw宽度和高度比实际文本大很多.人们可以期望TextVIEw的宽度和高度紧紧地包裹在文本周围.

下图显示了数字18和文本“SEC”未在同一底部基线上对齐的情况.这是因为较大的文本高度比文本大很多.我的xml布局如下所示.

如何实现更好的文本对齐精度?

<relativeLayout    androID:layout_wIDth="fill_parent"    androID:layout_height="0dp"    androID:layout_weight="1"    androID:background="@drawable/scan_block_1_bg" >    <linearLayout        androID:ID="@+ID/staticCountDown"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_centerInParent="true"        androID:gravity="center"        androID:orIEntation="vertical" >        <TextVIEw            androID:ID="@+ID/tvstaticScanning"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:shadowcolor="#ffffff"            androID:shadowDy="1.0"            androID:shadowRadius="0.01"            androID:text="SCANNING"            androID:textcolor="#878787"            androID:textSize="20sp" />        <TextVIEw            androID:ID="@+ID/tvCountDown"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:shadowcolor="#66000000"            androID:shadowDy="-1.0"            androID:shadowRadius="0.01"            androID:text="03"            androID:textcolor="#b6b6b6"            androID:textSize="81sp" />    </linearLayout>    <TextVIEw        androID:ID="@+ID/tvstaticSeconds"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignBottom="@ID/staticCountDown"        androID:layout_toRightOf="@ID/staticCountDown"        androID:gravity="left"        androID:shadowcolor="#ffffff"        androID:shadowDy="1.0"        androID:shadowRadius="0.01"        androID:text="SEC"        androID:textcolor="#878787"        androID:textSize="12sp" /></relativeLayout>

解决方法:

如果您查看屏幕截图,可能会发出奇怪的声音.两个文本视图都具有相同的底部对齐方式.尝试在电视倒计时中输入字母“gj”.实际上你可以看到两者都具有相同的底部对齐.最好用padma Kumar的答案.

总结

以上是内存溢出为你收集整理的android – TextView文本对齐太可怕了!如何解决它?全部内容,希望文章能够帮你解决android – TextView文本对齐太可怕了!如何解决它?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1105576.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存