Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put imageView just after textview in android

I am getting a problem in putting imageview just after textview if textview becomes of two line. I want to show this(Image just after text,text can be in one line,two line or three lines) enter image description here

My imageview comes just after textview if text is short(one line). But when text becomes longer(two lines) then image goes to next line like this enter image description here

I know the reason of this problem but don't know how to solve?

like image 990
Atul Bhardwaj Avatar asked Jan 15 '23 15:01

Atul Bhardwaj


1 Answers

After lot of googling, I found a good solution of my problem

TextView textView =new TextView(this);
                SpannableStringBuilder ssb = new SpannableStringBuilder( "Here's a smiley how are you " );
                Bitmap smiley = BitmapFactory.decodeResource( getResources(), R.drawable.movie_add );
                ssb.setSpan( new ImageSpan( smiley ), ssb.length()-1,  ssb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE );  
                textView.setText( ssb, BufferType.SPANNABLE );

With the help of above code, you can add image any where in Textview.

like image 140
Atul Bhardwaj Avatar answered Jan 17 '23 04:01

Atul Bhardwaj