在 TextView 末尾消失的字符

问题描述

我正在使用 SpannableStringBuilderTextView显示图像。但是,如果图像将停留在 TextView 中的行尾,它就会消失。如果我增加文本的大小,它将再次可见。我该如何解决

这是我在 TextView 中添加图像的代码

SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.setSpan(new ImageSpan(createClusterBitmap(idOfAyat)),ssb.length() - 1,ssb.length(),0);
itemViewHolder.kuranarabic.setText(ssb);

商品的 XML 代码

        <TextView
            android:id="@+id/kuranarabic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_margin="@dimen/_4sdp"
            android:fontFamily="@font/scheherazade"
            android:gravity="center_horizontal"
            android:textAlignment="center"
            android:textColor="?attr/color2"
            android:textSize="@dimen/_27sdp" />

我附上了两张图片。第一个是当停留在文本视图末尾时消失的图像。第二个出现在第一个位置时可见。

First Picture

Second Picture

First Picture if StackOverflow's link doesn't work

Second Picture if StackOverflow's link doesn't work

附言我将不胜感激任何帮助。这是我的第一个问题,不要那么强烈地评判我。 :)

解决方法

我通过向 Spannable String Builder 添加一个名为 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE 的标志解决了我的问题。

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" />

<div class="accordion" id="accordionExample">
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingOne">
      <button class="acc-btn accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                <span class="title">
                    1. The Eater Of Dreams
                </span>
                <span class="time">
                    0:52
                </span>
            </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is shown by default,until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance,as well as the showing and
        hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>,though the transition does limit overflow.
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingOne">
      <button class="acc-btn accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                <span class="title">
                    1. The Eater Of Dreams
                </span>
                <span class="time">
                    0:52
                </span>
            </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is shown by default,though the transition does limit overflow.
      </div>
    </div>
  </div>
</div>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...