当前位置: 移动技术网 > 移动技术>移动开发>Android > Android使用Shape实现ProgressBar样式实例

Android使用Shape实现ProgressBar样式实例

2019年07月24日  | 移动技术网移动技术  | 我要评论

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网