Android создает пирог с градиентом

Есть ли способ создать круг с таким градиентом?

введите описание изображения здесь

Насколько я понимаю, это:

<shape
       android:innerRadiusRatio="3"
       android:thicknessRatio="10"
       android:shape="ring">
     <gradient
               android:endColor="@color/cyan_dark"
               android:startColor="@color/red"
               android:type="radial"
               android:gradientRadius="340"
               android:centerX="50%"
               android:centerY="0" />
</shape>

person and_dev    schedule 12.01.2015    source источник
comment
Каков ваш реальный результат?   -  person MineConsulting SRL    schedule 12.01.2015


Ответы (4)


XML

<ProgressBar
        android:id="@+id/yourId"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="89dp"
        android:layout_height="89dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:max="100"
        android:progress="70"
        android:progressDrawable="@drawable/shapering" />

формирование с возможностью рисования

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadiusRatio="3"
    android:shape="ring"
    android:thicknessRatio="10" >

    <gradient
        android:centerColor="#D6DE47"
        android:centerX="50%"
        android:centerY="0"
        android:endColor="#DE47A7"
        android:gradientRadius="340"
        android:startColor="#6D47DE"
        android:type="sweep" />

</shape>

Результат

введите описание изображения здесь

person Murtaza Khursheed Hussain    schedule 12.01.2015
comment
спасибо за ваш повтор, но мне нужно поддержать также в 100 прогрессе, который в вашем ответе, если вы измените прогресс на 100, желтый эффект будет отображаться с обеих сторон, - person and_dev; 12.01.2015
comment
Я хочу что-то вроде этого, но вместо пустого я хочу серый цвет для пустой области, как я могу этого добиться? - person Harneet Kaur; 22.08.2016

использовать этот

 <ProgressBar
        android:id="@+id/progressWheel"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="152dp"
        android:layout_height="152dp"
        android:layout_centerInParent="true"
        android:progress="100"
        android:indeterminate="false"
        android:progressDrawable="@drawable/circular_progress_bar" />

в drawable round_progress_bar (измените цвет в соответствии с вашими потребностями)

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/progress">
    <rotate
        android:fromDegrees="270"
        android:toDegrees="270"
        android:pivotX="50%"
        android:pivotY="50%" >
        <shape
            android:innerRadiusRatio="2.5"
            android:shape="ring"
            android:thicknessRatio="25.0" >
            <gradient
                android:centerColor="@color/red"
                android:endColor="@color/gray"
                android:startColor="@color/gray"
                android:type="sweep" />
        </shape>
    </rotate>
</item>
<item android:id="@android:id/secondaryProgress">
    <rotate
        android:fromDegrees="270"
        android:toDegrees="270"
        android:pivotX="50%"
        android:pivotY="50%" >
        <shape
            android:innerRadiusRatio="2.5"
            android:shape="ring"
            android:thicknessRatio="25.0" >
            <gradient
                android:centerColor="@color/green"
                android:endColor="@color/green"
                android:startColor="@color/green"
                android:type="sweep" />
        </shape>
    </rotate>
</item>
</layer-list>    
person lalit vasan    schedule 12.01.2015

использовать этот

<ProgressBar
    android:id="@+id/progressWheel"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="152dp"
    android:layout_height="152dp"
    android:layout_centerInParent="true"
    android:progress="100"
    android:indeterminate="false"
    android:progressDrawable="@drawable/circular_progress_bar" />

в drawable round_progress_bar (измените цвет в соответствии с вашими потребностями)

 <?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:id="@android:id/progress">
<rotate
    android:fromDegrees="270"
    android:toDegrees="270"
    android:pivotX="50%"
    android:pivotY="50%" >
    <shape
        android:innerRadiusRatio="2.5"
        android:shape="ring"
        android:thicknessRatio="25.0" >
        <gradient
            android:centerColor="@color/red"
            android:endColor="@color/gray"
            android:startColor="@color/gray"
            android:type="sweep" />
    </shape>
</rotate>
</item>
<item android:id="@android:id/secondaryProgress">
<rotate
    android:fromDegrees="270"
    android:toDegrees="270"
    android:pivotX="50%"
    android:pivotY="50%" >
    <shape
        android:innerRadiusRatio="2.5"
        android:shape="ring"
        android:thicknessRatio="25.0" >
        <gradient
            android:centerColor="@color/green"
            android:endColor="@color/green"
            android:startColor="@color/green"
            android:type="sweep" />
    </shape>
 </rotate>
</item>
 </layer-list>    
person Harman Khera    schedule 12.01.2015

Вы должны использовать type = "sweep" вместо "radial", чтобы создать градиент, как на картинке. Например:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="7.0">
        <gradient
            android:startColor="#FF0000"
            android:centerColor="#00FF00"
            android:endColor="#0000FF"
            android:type="sweep" />
    </shape>
</item>

person inverse12    schedule 12.01.2015