简体   繁体   中英

How to make custom shape view that exactly shape of the image

I want to add image view like this "/ /" shape, problem is it covers rectangular space, and I want to make it clickable only in the shape of image, any solution?

I have added a picture in which I want to make view clickable only in black and red area, and should not be clickable in white area

I have to make view like this

You have to create a custom view for your purpose. Firstly in order to draw like the image you have shared, you should use PorterDuff modes. You can find details in link: PorterDuff.Modes .For drawing part you should create paths for slash shapes. To be able to make only masked areas clickable you should override onTouchEvent method. In this method you have to check x and y positions of touch events against the paths you have created at the drawing phase. If the touch event occurs in the area enclosed by the paths you should fire corresponding events.

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