繁体   English   中英

如何在Android中创建具有反面的形状

[英]How to create a shape with invert side in Android

我想创建一个如下图所示的形状,但是我不知道该怎么做。 我搜索了很多,但找不到正确的答案。

倒形

我可以用圆角做,但是我不想要。

这是我用于圆角的代码:

<?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/>
    <corners android:radius="10dp"/>
    <padding android:left="0dp" android:top="0dp" android:right="0dp"             
        android:bottom="0dp" />
</shape>

您可以使用SVG文件并将其转换为Vector Asset。 结果将是这样的:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="359dp"
    android:height="196dp"
    android:viewportWidth="359.5"
    android:viewportHeight="196.0">
<path
    android:pathData="M359.5,196H0V0h359.5V196zM294.25,155.07V40.93h-229c20.5,37.56 20.56,76.26 0,114.15H294.25z"
    android:fillColor="#FFD528"/>
</vector>

在res / drawable中将其保存为(例如)flag.xml,然后将其设置为ImageView作为srcCompat(例如):

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/flag"/>

不幸的是,这种方式将不允许您保留某些区域以免被拉长,因此您可能要使用可调整大小的位图(9补丁文件) 如果您实际上想使用此形状创建某些视图的蒙版,canvas.clipPath(Path)将为您提供帮助。 当前不支持将带有setConvexPath()的PS ViewOutlineProvider创建遮罩。

暂无
暂无

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

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