xml 自定义进度条圆和水平
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml 自定义进度条圆和水平相关的知识,希望对你有一定的参考价值。
ProgressBar progressBar = (ProgressBar) findViewById(R.id.circularProgressbar);
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 0, 75);
animation.setDuration(5000);
animation.setInterpolator(new DecelerateInterpolator());
animation.start();
/*
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.circular);
progressBar.setProgress(25); // Main Progress
progressBar.setSecondaryProgress(50); // Secondary Progress
progressBar.setMax(100); // Maximum Progress
progressBar.setProgressDrawable(drawable);
*/
ProgressBar progressBar1 = (ProgressBar) findViewById(R.id.progressbar1);
ObjectAnimator animation1 = ObjectAnimator.ofInt(progressBar, "progress", 0, 75);
animation1.setDuration(5000);
animation1.setInterpolator(new LinearInterpolator());
animation1.start();
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/secondaryProgress">
<shape android:innerRadiusRatio="3"
android:shape="ring" android:thicknessRatio="14.0"
android:useLevel="true">
<gradient android:centerColor="#999999"
android:endColor="#999999"
android:startColor="#999999"
android:type="sweep" />
</shape>
</item>
<item android:id="@android:id/progress">
<rotate android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="14.0"
android:useLevel="true">
<!--
<rotate android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
-->
<gradient android:centerColor="#00FF00"
android:endColor="#00FF00"
android:startColor="#00FF00"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
---------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding android:top="1dp" />
<solid android:color="#10444444" />
</shape>
</item>
<item>
<shape>
<padding android:top="1dp" />
<solid android:color="#20444444" />
</shape>
</item>
<item>
<shape>
<padding android:top="1dp" />
<solid android:color="#30444444" />
</shape>
</item>
<item android:id="@android:id/background">
<shape>
<solid android:color="@color/colorAccent" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#3500D0" />
</shape>
</clip>
</item>
</layer-list>
-------------------------------------------------------------------------------
<ProgressBar
android:id="@+id/circularProgressbar"
android:layout_width="250dp"
android:layout_height="250dp"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
android:progress="75"
android:max="100"
android:secondaryProgress="100"
android:progressDrawable="@drawable/circular" />
<ProgressBar
android:id="@+id/progressbar1"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:progressDrawable="@drawable/horizontal"
android:indeterminate="true"
android:layout_marginLeft="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="58dp"
app:layout_constraintTop_toBottomOf="@+id/circularProgressbar"
app:layout_constraintHorizontal_bias="0.0" />
以上是关于xml 自定义进度条圆和水平的主要内容,如果未能解决你的问题,请参考以下文章