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>
复制代码
修改后运行效果如下:
复制代码

复制代码
如果您感觉文章有用的话麻烦点个赞吧.
复制代码
复制代码
复制代码
相关推荐
lichong9511 天前
Android studio 修改包名
android·java·前端·ide·android studio·大前端·大前端++
爱学习的大牛1231 天前
MVVM 架构 android
android·mvvm
alexhilton1 天前
理解retain{}的内部机制:Jetpack Compose中基于作用域的状态保存
android·kotlin·android jetpack
꒰ঌ 安卓开发໒꒱1 天前
Mysql 坏表修复
android·mysql·adb
_李小白1 天前
【Android Gradle学习笔记】第八天:NDK的使用
android·笔记·学习
袁震1 天前
Android-Compose 列表组件详解
android·recyclerview·compose
2501_916007471 天前
提升 iOS 26 系统流畅度的实战指南,多工具组合监控
android·macos·ios·小程序·uni-app·cocoa·iphone
zh_xuan1 天前
android 利用反射和注解绑定控件id和点击事件
android·注解·反射·控件绑定
这个杀手不太累1 天前
Android ProcessLifecycleOwner
android·lifecycle
SRC_BLUE_171 天前
NSSCTF - Web | 【第五空间 2021】pklovecloud
android·前端