【问题标题】:justificationMode with LinkMovementMethod make text cut offjustificationMode 与 LinkMovementMethod 使文本被切断
【发布时间】:2021-08-05 03:31:21
【问题描述】:

我想同时实现对齐文本并添加一个链接(显示更多)到TextView,所以我使用justificationModemovementMethodjustificationMode 运行良好,但设置 movementMethod 后,我的 TextView 每一行的最后一个字符被剪切。

val textView = findViewById<TextView>(R.id.myTextView)
textView.text = "Lorem ipsum dolor sit amet, consectetuabc adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
textView.justificationMode = JUSTIFICATION_MODE_INTER_WORD
textView.movementMethod = LinkMovementMethod()

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/myTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="16dp"
        android:layout_marginTop="10dp"
        android:textSize="20sp" />

</LinearLayout>

【问题讨论】:

    标签: android textview


    【解决方案1】:

    我遇到了同样的问题,我找到的解决方案是在我的 Textview 上使用 android:autoLink="all" 标签,而不是使用 LinkMovementMethod...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 2021-10-05
      • 1970-01-01
      相关资源
      最近更新 更多