Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align drawableLeft to top instead center in android TextView?

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.

enter image description here

Is it possible to achieve this?

like image 563
androidcodehunter Avatar asked Sep 01 '14 10:09

androidcodehunter


1 Answers

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.

like image 89
Rahul M Mohan Avatar answered Sep 18 '22 21:09

Rahul M Mohan