Android使用Shape实现ProgressBar样式实例

2019/7/7 20:42:43

本文主要是介绍Android使用Shape实现ProgressBar样式实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

使用Shape实现样式

使用Shape中的ring实现,如下布局ring.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="ring"
  android:thickness="5dp"
  android:useLevel="false" >
  <gradient
    android:endColor="#888"
    android:startColor="#ccc"
    android:type="sweep"
    android:useLevel="false" />
</shape>

使用rotate使之旋转

如下progressbar.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <rotate 
      android:drawable="@drawable/ring"
      android:pivotX="50%"
      android:pivotY="50%"
      android:fromDegrees="0"
      android:toDegrees="1080"/>
  </item>
</layer-list>

注意:其中fromDegrees与toDegrees之差要是360的倍数,不然中间会有转的时候会跳一下,另外,这个差越大就转得越快,具体效果大家可以自行试一下

使用

<ProgressBar
  style="?android:attr/progressBarStyleLarge"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:indeterminateDrawable="@drawable/progressbar" <!-- 这里使用自定义的progressbar样式 -->
/>

更简单的方法

直接使用一个布局文件就可以实现:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromDegrees="0"
  android:pivotX="50%"
  android:pivotY="50%"
  android:toDegrees="1080" >

  <shape
    android:shape="ring"
    android:thickness="5dp"
    android:useLevel="false" >
    <gradient
      android:endColor="#888"
      android:startColor="#ccc"
      android:type="sweep"
      android:useLevel="false" />
  </shape>
</rotate>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。



这篇关于Android使用Shape实现ProgressBar样式实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程