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

复制代码
如果您感觉文章有用的话麻烦点个赞吧.
复制代码
复制代码
复制代码
相关推荐
安卓理事人6 小时前
安卓LinkedBlockingQueue消息队列
android
万能的小裴同学7 小时前
Android M3U8视频播放器
android·音视频
q***57748 小时前
MySql的慢查询(慢日志)
android·mysql·adb
JavaNoober8 小时前
Android 前台服务 "Bad Notification" 崩溃机制分析文档
android
城东米粉儿9 小时前
关于ObjectAnimator
android
zhangphil10 小时前
Android渲染线程Render Thread的RenderNode与DisplayList,引用Bitmap及Open GL纹理上传GPU
android
火柴就是我11 小时前
从头写一个自己的app
android·前端·flutter
lichong95112 小时前
XLog debug 开启打印日志,release 关闭打印日志
android·java·前端
用户693717500138412 小时前
14.Kotlin 类:类的形态(一):抽象类 (Abstract Class)
android·后端·kotlin
火柴就是我12 小时前
NekoBoxForAndroid 编译libcore.aar
android