drawableEnd textview 属性 无法在移动设备上运行 android
drawableEnd textview property not working in mobile android
你好朋友我想把我的可绘制图像放在我的 textview
的末尾,所以我将我的布局设置如下
xml 文件
<TextView
android:id="@+id/text_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_two"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Go ahead and get to the area you want then"
android:drawableEnd="@drawable/alogo_small"
android:textColor="@android:color/black"
android:textSize="@dimen/text_15"
android:visibility="visible" />
当我 运行 上面的代码让我输出如下
我想要在 then
之后绘制,所以知道如何解决这个问题吗?您的所有建议都是可取的
编辑
SpannableString ss = new SpannableString("Go ahead and get to the area you want then");
Drawable d = getResources().getDrawable(R.drawable.alogo_small);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, ss.length(), ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextViewEmailTwo.setText(ss);
当我 运行 上面的代码时,它给我的输出如下
尝试使用Html.ImageGetter:
Html.ImageGetter getter = new Html.ImageGetter(){
public Drawable getDrawable(String source){ // source is the resource name
Drawable d = null;
Integer id = new Integer(0);
id = getApplicationContext().getResources().getIdentifier(source, "drawable",getPackageName());
d = getApplicationContext().getResources().getDrawable(id);
if (d != null)
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
String imgString = "Go ahead and get to the area you want then " + " <img src=\"alogo_small\"/>";
mTextViewEmailTwo.setText(Html.fromHtml(imgString, getter, null));
你好朋友我想把我的可绘制图像放在我的 textview
的末尾,所以我将我的布局设置如下
xml 文件
<TextView
android:id="@+id/text_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_two"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Go ahead and get to the area you want then"
android:drawableEnd="@drawable/alogo_small"
android:textColor="@android:color/black"
android:textSize="@dimen/text_15"
android:visibility="visible" />
当我 运行 上面的代码让我输出如下
我想要在 then
之后绘制,所以知道如何解决这个问题吗?您的所有建议都是可取的
编辑
SpannableString ss = new SpannableString("Go ahead and get to the area you want then");
Drawable d = getResources().getDrawable(R.drawable.alogo_small);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, ss.length(), ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextViewEmailTwo.setText(ss);
当我 运行 上面的代码时,它给我的输出如下
尝试使用Html.ImageGetter:
Html.ImageGetter getter = new Html.ImageGetter(){
public Drawable getDrawable(String source){ // source is the resource name
Drawable d = null;
Integer id = new Integer(0);
id = getApplicationContext().getResources().getIdentifier(source, "drawable",getPackageName());
d = getApplicationContext().getResources().getDrawable(id);
if (d != null)
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
String imgString = "Go ahead and get to the area you want then " + " <img src=\"alogo_small\"/>";
mTextViewEmailTwo.setText(Html.fromHtml(imgString, getter, null));