本文介绍了如何将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.

有可能实现这一目标吗?

Is it possible to achieve this?

推荐答案

使用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中居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:45