【发布时间】:2023-12-01 21:47:02
【问题描述】:
我制作了一个可绘制的按钮,它由渐变形状和实心形状组成,两者都在这样的图层列表中:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:height="25dp">
<shape android:shape="rectangle" >
<gradient
android:angle="90"
android:startColor="@color/greyDark1"
android:endColor="@color/greyDark2"/>
</shape>
</item>
<item android:top="25dp" android:height="25dp">
<shape android:shape="rectangle" >
<solid android:color="@color/black" />
</shape>
</item>
</layer-list>
但我无法正确处理角落。 我需要整个形状周围的圆角,而不是内部(所以 topRight 和 topLeft 操作上半部分,bottomRight 和 bottomLeft 用于下半部分)。
如果我将两半都设置为<corners android:radius="8dp">,则上半部分的底角和下半部分的顶角也是圆角的,这不是我想要的。
如果我将<corners android:topRightRadius="8dp" android:topLeftRadius"8dp"> 设置为上半部分,<corners android:bottomRightRadius="8dp" android:bottomLeftRadius"8dp"> 设置为下半部分,则上半部分将是可绘制对象的完整大小,导致渐变无法正常工作,并且底角也是相同的颜色。
这是我想要完成的图像:
有人知道解决办法吗?
编辑:
我得到了一些答案,对此我很感激,但遗憾的是它们似乎不起作用。
我从 bofredo 和 Bhuvnesh Chasta 得到的答案是这样的:
而且我从奇怪的头脑得到的答案看起来很不错,但不是我的目标:
最终编辑:
我已经和我一起工作的人讨论过这个问题,我们都同意让它看起来不是那么重要,所以我们选择了纯色。
我仍然要感谢所有提供帮助的人,所有当前的答案都会得到支持,我会接受 waqaslam 的答案,因为他非常接近我想要的。
【问题讨论】:
-
图片可以随意展示吗?
-
*.com/q/15100660/5093666 @Dennis 试试这个
-
@curiousMind 我在编辑中添加了一张图片,我真的很想用 android xml 设置这些角落
-
看我的答案兄弟......
标签: android xml drawable rounded-corners layer-list