虽然试图给ImageSpan
前面textview
我在平板电脑上的线条之间获得了额外的空间,例如 Nexus 7
但是在 Nexus5x 上没问题
public void setTitleWithItemCount(String name, int itemCount, @StringRes int singularResID, @StringRes int pluralRedID) {
final String itemNoun = itemCount == 1 ? getResources().getString(singularResID) : getResources().getString(pluralRedID);
final String title = getResources().getString(R.string.work_summary_tile_title,
" " + name,
itemCount,
itemNoun);
final SpannableStringBuilder workItemTxt = new SpannableStringBuilder(title);
Drawable d = getResources().getDrawable(actionImage);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
workItemTxt.setSpan(span, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
workItemTxt.setSpan(new TextAppearanceSpan(getContext(), R.style.WorkItemTitleText),
1,
name.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
workItemTxt.setSpan(new TextAppearanceSpan(getContext(), R.style.WorkItemSubTitleText),
name.length(),
title.length() + 1,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
titleView.setText(workItemTxt);
}
xml
<TextView
android:id="@+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_marginStart="-20dp"
android:layout_toEndOf="@+id/image_container"
android:layout_toStartOf="@id/progress_title"
android:ellipsize="end"
android:lines="3"
android:maxLines="3"
android:textAppearance="@style/WorkItemTitleText"
tools:text="@string/lorem_ispum_short"/>
我该如何解决这个问题?任何帮助表示赞赏