-1

Currently developing new view for text and image SEND/RECEIVE application betweeb Client and Server.

I have created row.xml for Row view like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/msgLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/msgText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5sp"
        android:background="@drawable/speech_bubble_green"
        android:drawableTop="@drawable/ic_content_picture"
        android:shadowColor="@color/textShadow"
        android:shadowDx="1"
        android:shadowDy="1"
        android:textSize="0sp" />

</LinearLayout>

Now i want to set drawableTop programmatically without text when i got image to send or receive.

While sending i have picked up image from gallery and it returns Bitmap object.

How can i set that Bitmap object as drawableTop Programmatically.?

P.S.

I have seen this StackOverflow answer but It works for Drawable Id.

Your help would be appreciated.

Community
  • 1
  • 1
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437

1 Answers1

3

You can use following:

Drawable d = new BitmapDrawable(bm);
d.setBounds(0, 0, bm.getWidth(), bm.getHeight());
textView.setCompoundDrawables(null, d, null, null);
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Niko
  • 8,093
  • 5
  • 49
  • 85