0
votes

I have a text-view and a bitmap. Now, I want to draw this bitmap on the canvas of the text-view. Is there any way I can obtain the canvas of the text-view, to draw the bitmap onto it ?

I know, I can achieve similar results by wrapping the bitmap into a bitmapdrawable, & setting the background of the text-view to this bitmapdrawable like this: textView.setBackground(new BitmapDrawable(getResources(), bitmap)); This operation needs to take place while UI interaction, so I do not want to do this way, as it requires creation of a bitmapdrawable object every time, & android does not recommend creating objects during UI interaction.

Can anybody suggest some other way to achieve similar results, which has least overhead. Or is there anyway I can get the canvas of the textview object I am working on & directly draw the bitmap onto it ?

If anybody has worked in this area before, please help !

1
Did you try overriding the onDraw method of the text view? You may draw the bitmap on canvas there.Ercan
@Ercan I will need to extend the textview class to acheive this, as Rajesh CP suggested, but I do not want to do this, as I am working with legacy code, which uses text view object. Do you know of any other way, I can acheive this ?superuser

1 Answers

1
votes

extend the TextView Class and override the onDraw method

Protected void onDraw(Canvas canvas){
    super.onDraw(canvas);
}

Did not tested out the code. But this would be the way I would be going with.