安卓:如何通过xml制作圆形外观类似光晕的图形

3

我正在尝试使用XML制作一个带光晕的圆形。光晕应该从中心开始是绿色,逐渐淡化为边缘处的透明。

如何实现呢?

我尝试使用以下方法:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <gradient   android:centerColor="@drawable/light_green" android:gradientRadius="250" android:type="radial"
         android:endColor="@android:color/transparent"
        android:angle="270"/>
</shape>

仍然无法获得所需的效果。任何线索都将有所帮助。


为什么不使用自定义视图? - Raghunandan
1个回答

5

试试这个:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >

    <gradient
        android:angle="270"
        android:centerColor="#88FF0000"
        android:centerX="50%p"
        android:centerY="50%p"
        android:endColor="#00FF0000"
        android:gradientRadius="50%p"
        android:startColor="#FFFF0000"
        android:type="radial" />
       <size
           android:height="80dp"
           android:width="80dp" />

</shape>

根据您的要求更改颜色代码并更改centerColor的alpha代码


1
将此应用于我的视图背景后,只有一个非常非常小的点是可见的,没有其他东西。 - Ritu Raj
它对我仍然没有起作用,但是当我将gradientRaidus更改为70时,它就可以工作了:)。谢谢。 - Ritu Raj
美丽的光芒 <3 - Maveňツ

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