How can I make sine wave on an Imageview in android?

半世苍凉 提交于 2019-12-21 06:36:26

问题


I want to create image similar to this.

Is it possible to be done in XML? If not, how would I scale an image that is shape like this?


回答1:


Yes it's possible , you can use vactor drawable for it

    <?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>

like this image




回答2:


It is achieve by Canvas.drawPath to draw any path on your canvas. To draw sine path, you have to step through the function values of the sine with a small delta and add each point to the path with Path.lineTo.

For more reference... https://developer.android.com/reference/android/graphics/Path.html#lineTo%28float,%20float%29




回答3:


i have something that's similar to this not exactly the same.hope this may help you

<?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>



来源:https://stackoverflow.com/questions/43468066/how-can-i-make-sine-wave-on-an-imageview-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!