Android XML:绘制带有 diamond/rhombus 边框的 Stack Overflow 图形设计 diamond/rhombus 按钮

Android XML: drawing StackOverflow's GraphicDesign's diamond/rhombus button with diamond/rhombus borders

我想使用与此按钮相同的边框: (cf.: https://graphicdesign.stackexchange.com/)。是否可以使用 radius XML 属性(borderLeftTopRadius 等)来实现?或者我必须使用一些图片吗?

您可以使用向量来做到这一点。它在 android 工作室中可用。单击此 link 了解更多信息。 Add multi-density vector graphics

默认的 android xml 代码只会帮助您实现带有一些渐变的圆角和虚线边框。

只需创建一个 Drawable 资源文件即可:custom_button.xml

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="153.77dp"
android:height="41.33dp"
android:viewportWidth="153.77"
android:viewportHeight="41.33">

<path
    android:strokeColor="#e94b5a"
    android:strokeWidth="1"
    android:strokeMiterLimit="10"
    android:pathData="M 9.89 0.5 L 144.22 0.5 L 153.22 20.5 L 144.22 40.83 L 10.22 
40.83 L 0.55 20.5 L 9.89 0.5 Z" />
</vector>

然后将其作为按钮的背景:

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="ask question"
    android:textColor="#E94A5A"
    android:background="@drawable/custom_button"/>

截图:

Screenshot