如何在Android上的ImageView上生成正弦波?

3

我想创建类似于这个的图片。

CardView Item

这个能用XML实现吗?如果不能,那么我该如何缩放这样形状的图片?

3个回答

1

是的,这是可能的,您可以使用vactor drawable来实现。

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

<path
    android:fillColor="#000000"
    android:fillAlpha="0"
    android:strokeColor="#000000"
    android:strokeWidth="1"
    android:pathData="" />
<path
    android:fillColor="#000000"
    android:fillAlpha="0"
    android:strokeColor="#000000"
    android:strokeWidth="1"
    android:pathData="" />
<path
    android:fillColor="#000000"
    android:strokeWidth="1"
    android:pathData="M0 640L637.5 640L637.5 519.77C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 640Z" />
<path
    android:fillColor="#000000"
    android:fillAlpha="0"
    android:strokeColor="#000000"
    android:strokeWidth="1"
    android:pathData="M0 640L637.5 640L637.5 519.77C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 640Z" />
<path
    android:fillColor="#000000"
    android:fillAlpha="0"
    android:strokeColor="#000000"
    android:strokeWidth="1"
    android:pathData="M0 640L637.5 640L637.5 519.77C528.33 483.94 424.58 482.69 326.25 516.02C227.91 549.35 119.17 545.6 0 504.77L0 640Z" /></vector>

像这样的图像在此输入图片描述

0

0

我有类似的东西,虽然不完全一样。希望这能对你有所帮助。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:height="50dp"
    android:gravity="bottom">
    <shape android:shape="rectangle">
        <solid android:color="#ffff0000" />
    </shape>
</item>
<item
    android:width="500dp"
    android:height="60dp"
    android:gravity="bottom|center_horizontal"
    android:top="-0dp">
    <shape android:shape="oval">
        <solid android:color="#ffffffff" />
    </shape>
</item>
<item
    android:height="20dp"
    android:bottom="30dp"
    android:gravity="bottom">
    <shape android:shape="rectangle">
        <solid android:color="#ffffffff" />
    </shape>
</item>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接