如何在android中的Imageview上制作正弦波?

问题描述 投票:0回答:3

我想创建与此类似的图像。

CardView Item

是否可以用XML完成?如果没有,我将如何缩放形状如此的图像?

android vector imageview android-imageview
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>

喜欢这个imageenter image description here


0
投票

它由Canvas.drawPath实现在画布上绘制任何路径。要绘制正弦路径,您必须使用小增量逐步调整正弦函数值,并使用Path.lineTo将每个点添加到路径。

有关更多参考... https://developer.android.com/reference/android/graphics/Path.html#lineTo%28float,%20float%29


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>

© www.soinside.com 2019 - 2024. All rights reserved.