gpt4 book ai didi

android - drawableEnd textview 属性在移动 android 中不起作用

转载 作者:行者123 更新时间:2023-11-29 20:43:33 25 4
gpt4 key购买 nike

你好 friend 我想要我的可绘制图像到我的 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" />

当我运行上面的代码时,它会像下面这样输出

enter image description here

我想要在 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);

当我运行上面的代码时,它会给我如下输出

enter image description here

最佳答案

尝试使用 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));

关于android - drawableEnd textview 属性在移动 android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com