0

I am trying to add a bitmap image inside a textview which is encoded and stored in DataBase useing base64 encode. i am using the following code

byte[]img= Base64.decode(cur.getString(2),Base64.DEFAULT);

 Drawable qDrawable = new BitmapDrawable(ctx.getResources(),BitmapFactory.decodeByteArray(img,0,img.length));

 question.setCompoundDrawablesWithIntrinsicBounds(null,null,qDrawable,null);

this code work good but

the problem is the image width doesn't fit textview width

I tryied to use ScaleType in xml but the textview doesn't have this property like imageview so how I can fix this issue with textview

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Ben Ghaleb
  • 463
  • 4
  • 9
  • 20
  • You are setting `CompoundDrawable` . instead of this use a `ImageView` with `TextView`. – ADM Mar 21 '18 at 04:34
  • `"doesn't fit textview width"`so what does it fit? you called `setCompoundDrawablesWithIntrinsicBounds` so it uses its own intrinsic size - see `TextView#setCompoundDrawablesWithIntrinsicBounds` method source implementation – pskink Mar 21 '18 at 05:32
  • @pskink part of image is hidden but if i rotate the screen i see image perfectly – Ben Ghaleb Mar 21 '18 at 05:50
  • see `TextView#setCompoundDrawablesWithIntrinsicBounds` method source implementation – pskink Mar 21 '18 at 05:52

1 Answers1

0

You need to resize your bitmap before setting it. Use Drawable.setBounds() and View.setCompoundDrawables() to achieve the desired width and height.

Example here.

Adib Faramarzi
  • 3,798
  • 3
  • 29
  • 44