本篇文章给大家分享的是有关Android应用中的ProgressBar样式怎么利用Shape实现,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
使用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
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应用中的ProgressBar样式怎么利用Shape实现,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。