请帮我翻译成程序化的progressDrawable。我需要三种颜色:
<gradient
android:id="@+id/progressCompensationColor"
android:startColor="@color/colorCompensationEasyGreen"
android:centerColor="@color/colorCompensationMediumGreen"
android:endColor="@color/colorCompensationHardGreen"
android:centerX="0.3"
android:type="sweep" />
MainDashboardFragment.kt
var colorEasy = ContextCompat.getColor(activity as MainActivity, R.color.colorProgressBlueLight)
var colorMedium = ContextCompat.getColor(activity as MainActivity, R.color.colorProgressBlueLight)
var colorHard = ContextCompat.getColor(activity as MainActivity, R.color.colorProgressBlueLight)
if (value <= 33.0) {
colorEasy = ContextCompat.getColor(activity as MainActivity, R.color.colorRedEasy)
colorMedium = ContextCompat.getColor(activity as MainActivity, R.color.colorRedMedium)
colorHard = ContextCompat.getColor(activity as MainActivity, R.color.colorRedHard)
} else if (value >= 66.0) {
colorEasy = ContextCompat.getColor(activity as MainActivity, R.color.colorGreenEasy)
colorMedium = ContextCompat.getColor(activity as MainActivity, R.color.colorGreenMedium)
colorHard = ContextCompat.getColor(activity as MainActivity, R.color.colorGreenHard)
}val customProgessBar = view.findViewById<ProgressBar>(R.id.progressCompensationScore)
fragment_main_dashboard_paired.xml
<com.mysasy.mysasymobile.ui.CustomProgressBar
android:id="@+id/progressCompensationScore"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="@drawable/background_progress_bar_circular_blue"
android:indeterminate="false"
android:min="50"
android:max="150"
android:progress="75"
android:progressDrawable="@drawable/progress_circle" />
progress_circle.xml
<item>
<shape
android:innerRadiusRatio="2.15"
android:shape="ring"
android:thicknessRatio="50.0" >
<gradient
android:id="@+id/progressCompensationColor"
android:startColor="@color/colorCompensationEasyGreen"
android:centerColor="@color/colorCompensationMediumGreen"
android:endColor="@color/colorCompensationHardGreen"
android:centerX="0.3"
android:type="sweep" />
</shape>
</item>
实施?这是正确的程序吗?
val customProgessBar = view.findViewById<ProgressBar>(R.id.progressCompensationScore)
val draw = createProgressBar(Color.RED, Color.GREEN, Color.BLUE)
customProgessBar.progressDrawable = draw
我的灵感:渐变圆形进度条