简体   繁体   English

Android - 如何创建带圆角和平铺图像背景的视图?

[英]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). 我正在尝试在Android中创建一个具有圆角的视图,并且还使用平铺图像背景(并且显示在具有平铺背景的另一视图的顶部)。

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 http://developer.android.com/reference/android/graphics/Path.html

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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