我的TextView
填充了应包含一些ImageSpan
个对象的文本。图像可能高于法线高度,导致以下问题:
更有趣的是,如果文本中有换行符,那么从那一点开始,行高就会很好。
TextView
只是一个非常基本的问题:
<TextView
android:id="@+id/text_02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="18dp"
android:text="Text 02" />
(TextView
位于LinearLayout
中的ScrollView
。
这就是我创建跨区文本的方式:
TextView textView02 = (TextView) findViewById(R.id.text_02);
SpannableString string = new SpannableString(LOREM_IPSUM);
string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), 102, 103, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), 105, 106, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
string.setSpan(new ImageSpan(this, R.mipmap.ic_launcher), 108, 109, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView02.setText(string);
有人对此有任何解决方案吗?我宁愿不重新实现TextView
的线条绘制方法......
答案 0 :(得分:0)
尝试使用ImageSpan
设置要显示的drawable的高度。例如:
Drawable vegetary = mContext.getResources().getDrawable(R.drawable.ic_best_veget);
vegetary.setBounds(0, 0, vegetary.getIntrinsicWidth(), <yourHeight>);
ssb.setSpan(new ImageSpan(vegetary, ImageSpan.ALIGN_BASELINE), ssb.length()-1, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);