简体   繁体   中英

Android - How to create a view with rounded corners and a tiled image background?

I'm trying to create a view in Android that has rounded corners and also uses a tiled image background (and which appears on top of another view with a tiled background).

I can create a shape drawable for the corners and a bitmap drawable for the tiled image, but I can't see how I can apply them both the same view.

Some things I've attempted:

  • Nesting the view with the tiled background inside a view with rounded corners - doesn't work, the tiled background just appears on top with square corners

  • Paint over the corners of the view with rounded corners - this doesn't work because of the tiled background of the view below (otherwise would work fine)

I believe your custom View should define its drawing region with a Path. You could then draw the Path with a paint and shader doing what you want (fill and tile).

http://developer.android.com/reference/android/graphics/Path.html

您可以在不使用硬件加速不支持的clipPath情况下检查包含此方法的视频

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