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

复制代码
如果您感觉文章有用的话麻烦点个赞吧.
复制代码
复制代码
复制代码
相关推荐
游戏开发爱好者83 分钟前
对 iOS IPA 文件进行深度混淆的一种实现路径
android·ios·小程序·https·uni-app·iphone·webview
成都大菠萝8 分钟前
2-2-5 快速掌握Kotlin-语言的泛型函数
android
成都大菠萝8 分钟前
2-2-4 快速掌握Kotlin-定义泛型类
android
掘我的金10 分钟前
加载状态优化实践:如何让用户始终知道当前状态
android
成都大菠萝11 分钟前
2-2-6 快速掌握Kotlin-语言的多泛型参数学习
android
掘我的金15 分钟前
空状态优化实践:如何让"白屏"变成友好的提示
android
_李小白21 分钟前
【Android FrameWork】第三十四天:系统设置项(Settings)与系统属性(System Properties)
android·jvm·oracle
、BeYourself1 小时前
GridLayoutManager 网格布局与 RecyclerView 拖拽侧滑实战
android·android-studio
Kapaseker1 小时前
如何写出高性能的Java Stream
android·java
tangweiguo030519871 小时前
Android 插件化开发完全指南(Kotlin DSL/Gradle KTS 配置)
android·kotlin