Android实现ProgressBar Android使用Shape实现ProgressBar样式实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Android实现ProgressBar Android使用Shape实现ProgressBar样式实例

AlvinL   2021-03-24 我要评论
想了解Android使用Shape实现ProgressBar样式实例的相关内容吗,AlvinL在本文为您仔细讲解Android实现ProgressBar的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:progressbar,样式,安卓progressbar样式,设置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>

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们