让android系统中任意一个view变成进度条
1.效果
2.进度条背景drawable文件
结束后可以恢复原背景.
1 <?xml version="1.0" encoding="utf-8"?> 2 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 3 <item android:id="@+id/background"> 4 <shape 5 android:layout_width="wrap_content" 6 android:shape="rectangle"> 7 <corners android:radius="12dp" /> 8 <stroke android:color="#dcdcdc" android:width="1px" ></stroke> 9 <solid android:color="#f7f7f7" /> 10 </shape> 11 </item> 12 <item android:id="@+id/progressing" 13 android:top="2px" 14 android:right="2px" 15 android:bottom="2px" 16 android:left="2px"> 17 <clip 18 android:clipOrientation="horizontal" 19 android:gravity="left" android:shape="rectangle"> 20 <shape> 21 <corners android:radius="12dp" /> 22 <solid android:color="#fee2cd" /> 23 </shape> 24 </clip> 25 </item> 26 </layer-list>
3.更新进度
在进度更新代码里 计算出进度值pro,然后更新.
1 LayerDrawable ld = (LayerDrawable) view.getBackground(); 2 ClipDrawable clipDrawable = (ClipDrawable) ld.findDrawableByLayerId(R.id.progressing); 3 clipDrawable.setLevel(100 * pro);
4.下载
https://gitee.com/xi/any-view-progress.git