Android TextView自动换行文本显示不全解决

某些情况下,TextView自动换行后,会出现每行结尾处显示不全的问题,

如图:

常见解决方案:

  1. 设置TextView的"ellipsize"属性为"end" 实测无效!
  2. 将TextView外部的Layout改为RelativeLayout 实测无效!
  3. 自定义TextView 过于繁琐且影响性能!

实际解决方案:

只需要设置TextView一个属性就可以解决,这个属性比较冷门:breakStrategy 意为换行策略,

将breakStrategy设置为"balanced"成功解决问题

代码如下:

html 复制代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/win_item_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:breakStrategy="balanced"
        android:ellipsize="end"
        android:maxLines="100"
        android:text="原文"
        android:textColor="@color/white"
        android:textSize="14dp" />

    <TextView
        android:id="@+id/win_item_tv_t"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/win_item_tv"
        android:breakStrategy="balanced"
        android:ellipsize="end"
        android:maxLines="100"
        android:paddingTop="2dp"
        android:text="译文"
        android:textColor="#fbbf48"
        android:textSize="14dp" />

</RelativeLayout>
复制代码
修改后运行效果如下:
复制代码

复制代码
如果您感觉文章有用的话麻烦点个赞吧.
复制代码
复制代码
复制代码
相关推荐
钛态3 小时前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
王码码20353 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)
android·前端·git·flutter·搜索引擎·云原生·harmonyos
左手厨刀右手茼蒿3 小时前
Flutter for OpenHarmony: Flutter 三方库 shamsi_date 助力鸿蒙应用精准适配波斯历法(中东出海必备)
android·flutter·ui·华为·自动化·harmonyos
代码飞天3 小时前
wireshark的高级使用
android·java·wireshark
2501_915918414 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
skiy4 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
小小小点5 小时前
Android四大常用布局详解与实战
android
MinQ6 小时前
binder和socket区别及原理
android
Ehtan_Zheng6 小时前
Jetpack Compose 中绘制发光边框的多种方式
android
智塑未来6 小时前
像素蛋糕安卓版 AI 专业修图全场景输出高清成片
android·人工智能