如何将drawableLeft对齐到顶部而不是在android TextView中居中? [英] How to align drawableLeft to top instead center in android TextView?

查看:31
本文介绍了如何将drawableLeft对齐到顶部而不是在android TextView中居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TextView 中,我将 drawableLeft 设置在 drawable 从中心显示的位置.我需要像这张图片一样将 drawableLeftTextView 内的顶部对齐.

In TextView I set drawableLeft where the drawable is showing from center. I need to align the drawableLeft with top inside TextView like this image.

有可能实现吗?

推荐答案

使用 SpannableString 和 ImageSpan 来实现.

Use SpannableString and ImageSpan to achieve this.

String msg=" "+"haii";
ImageSpan mImageSpan== new ImageSpan(mContext, R.drawable.icon);
SpannableString text = new SpannableString(msg);
text.setSpan(mImageSpan, 0, 1, 0);
mTextView.setText(text);

字符串变量中多余的空格被图标替换.

the extra space in the string variable is replaced by the icon.

这篇关于如何将drawableLeft对齐到顶部而不是在android TextView中居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆