Android: How to make Circle through xml which look

2019-07-10 02:40发布

问题:

I am trying to make a circle using xml with a halo. The halo would be like it starts with say green color in the center, the greenish color keeps fading and finally at the edges it becomes transparent.

How to go about it?

I am trying to use following:

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

Still not able to get the desired effect. Any lead would be helpful.

回答1:

Try this:

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

Change color code and change centerColor's alpha code as per your requirement