The Open source project Progresswheel provides us with a wide variety of circular scrollbars, which this article leads readers to use to implement custom scroll bars. In the official demo, a screen shows several styles, and this article only describes one style, that is, centered display, transparent layout. And with static encapsulation, both start and close require a single line of code to complete.
Open Source Project Progresswheel address:
Https://github.com/Todd-Davies/ProgressWheel
Open Source Project Progresswheel:
The implementation of a custom scrollbar (transparency effect):
1). xml:
<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"Xmlns:progresswheel="Http://schemas.android.com/apk/res-auto"Android:id="@+id/layout_progress_wheel"Android:layout_width="Fill_parent"android:layout_height="Match_parent"android:layout_gravity="Center"android:orientation="Vertical"> <com.todddavies.components.progressbar.progresswheel android:id="@+id/pw_spinner"Android:layout_width="100DP"android:layout_height="100DP"android:layout_gravity="Center"Progresswheel:barcolor="#0097D6"Progresswheel:barlength="100DP"Progresswheel:barwidth="5DP"Progresswheel:rimcolor="#330097D6"Progresswheel:rimwidth="10DP"progresswheel:text="Loading ..."Progresswheel:textcolor="#222"Progresswheel:contourcolor="#330097D6"Progresswheel:textsize="14SP"/></linearlayout>
2). Style:
<style name="Dialog" parent="android:style/Theme.Dialog"> <item name="android:background">#00000000</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> </style>
3). Java Code:
Public class loadingcommentdialog { Private StaticDialog Mdialog =NULL;Private StaticProgresswheel Mprogresswheel =NULL; Public Static void Showcommentdialog(Context context, String text) {Closecommentdialog (context); WindowManager m = (Activity) context). Getwindowmanager (); Display d = m.getdefaultdisplay ();//Get screen width, high-useMdialog =NewDialog (context, r.style.dialog); Layoutinflater Inflater = (Activity) context). Getlayoutinflater (); View layout = Inflater.inflate (R.layout.layout_progress_wheel,NULL); Mdialog.setcontentview (layout); Mprogresswheel = (progresswheel) Layout.findviewbyid (R.id.pw_spinner); Mprogresswheel.settext (text); Window Dialogwindow = Mdialog.getwindow ();//Windowmanager.layoutparams LP = Dialogwindow.getattributes (); lp.gravity = Gravity.center;//lp.x = 20;//new position X coordinate //lp.y = 60;//new position y-coordinateLp.width = D.getwidth ()- -;//Width //lp.height = (int) (D.getheight () *0.4);//HeightDialogwindow.setattributes (LP); Mprogresswheel.spin (); Mdialog.show (); } Public Static void Closecommentdialog(Context context) {if(mprogresswheel!=NULL) {mprogresswheel.stopspinning (); Mprogresswheel =NULL; }if(mdialog!=NULL) {Mdialog.dismiss (); Mdialog =NULL; } }}
4). Call Method:
//这里可以自定义圆形中的文字。//YourFouction() //这里,是开始你的线程,或者异步请求,或者耗时的操作...关闭:LoadingCommentDialog.closeCommentDialog(mContext);
Finally, attach the custom scroll bar (transparency effect):
The power of open source is endless!
Custom circular scrollbar (transparency effect)--take advantage of open source project Progresswheel