android用渐变创建饼图

标签 android android-drawable radial-gradients

有没有什么办法可以像这样创建带有渐变的圆圈?

enter image description here

据我所知是这样的:

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

最佳答案

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>

结果

enter image description here

关于android用渐变创建饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27898737/

相关文章:

android - 在 Android 中将布局添加为 View

android - 将 SVG 矢量转换为 Android 多密度 png 可绘制对象

android - 为什么Android无法识别颜色状态列表文件?

android - setProgressDrawble 正在填充整个进度条

css - 径向渐变显示一些背线,间隙,空格或边距

swift - CABasicAnimation 创建 CALayer 的空默认值副本

ios - 使用 Swift 5.1 for iOS 中的 SwiftUI 使用尺寸完美适合的 RadialGradient 填充动态大小的矩形

java - 如何使用 JNI 在 Android 中包含不可修改的原生 C++?

Android:当使用选择器 XML 按下按钮时,如何更改 TextView 的颜色

android - qt 传感器上的未定义引用