简体   繁体   中英

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:

在此处输入图片说明

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:

在此处输入图片说明

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM