在 TextView 末尾消失的字符

时间:2021-05-21 18:00:43

标签: java android textview imageview spannable

我正在使用 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

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

1 个答案:

答案 0 :(得分:0)

我通过向 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, 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>