Valentino Ru
Valentino Ru

Reputation: 5052

Set semi-transparent drawable on top of TextView at runtime

In an application to manage the costs of a living community, an user can 'terminate' a month, which is then stored in a database.

In a specific Activity of this app, there are shown the last four months including their attribute 'terminated'. I want to show this to the user by putting a semi-transparent hook on top of the TextView containing this month. Consider this image as example:

enter image description here

It seems that this doesn't work properly in Android.

textView.setCompoundDrawablesWithIntrinsicBounds(...)

does put the image on top, and it's semi-transparent too, but the initial text of the TextView disappears. Additionally, since now I haven't discovered yet how to scale the image into that TextView.

This is the actual output:

enter image description here

Can anybody help me with that? Should I define the scaling parameters directly in the XML layout file?

Upvotes: 2

Views: 240

Answers (1)

Blackbelt
Blackbelt

Reputation: 157447

You have to use a FrameLayout that wrap your TextView and an ImageView. The ImageView will contains the semitransparent drawable. In this way the will overlap

Upvotes: 1

Related Questions