ProgressBar进度条.docx
- 文档编号:9102133
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:30
- 大小:23.72KB
ProgressBar进度条.docx
《ProgressBar进度条.docx》由会员分享,可在线阅读,更多相关《ProgressBar进度条.docx(30页珍藏版)》请在冰豆网上搜索。
ProgressBar进度条
ProgressBar进度条
extendsView
java.lang.Object
↳android.view.View
↳android.widget.ProgressBar
KnownDirectSubclasses
AbsSeekBar,ContentLoadingProgressBar
KnownIndirectSubclasses
AppCompatRatingBar,RatingBar,SeekBar
ClassOverview
Visualindicatorofprogressinsomeoperation.Displaysabartotheuserrepresentinghowfartheoperationhasprogressed;theapplicationcanchangetheamountofprogress(modifyingthelengthofthebar)asitmovesforward.Thereisalsoasecondaryprogressdisplayableonaprogressbarwhichisusefulfordisplayingintermediateprogress,suchasthebufferlevelduringastreamingplaybackprogressbar.
Aprogressbarcanalsobemadeindeterminate.Inindeterminatemode,theprogressbarshowsacyclicanimationwithoutanindicationofprogress.Thismodeisusedbyapplicationswhenthelengthofthetaskisunknown.Theindeterminateprogressbarcanbeeitheraspinningwheelorahorizontalbar.
Thefollowingcodeexampleshowshowaprogressbarcanbeusedfromaworkerthreadtoupdatetheuserinterfacetonotifytheuserofprogress:
publicclassMyActivityextendsActivity{
privatestaticfinalintPROGRESS=0x1;
privateProgressBarmProgress;
privateintmProgressStatus=0;
privateHandlermHandler=newHandler();
protectedvoidonCreate(Bundleicicle){
super.onCreate(icicle);
setContentView(R.layout.progressbar_activity);
mProgress=(ProgressBar)findViewById(R.id.progress_bar);
//Startlengthyoperationinabackgroundthread
newThread(newRunnable(){
publicvoidrun(){
while(mProgressStatus<100){
mProgressStatus=doWork();
//Updatetheprogressbar
mHandler.post(newRunnable(){
publicvoidrun(){
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
}
Toaddaprogressbartoalayoutfile,youcanusethe
style="@android: style/Widget.ProgressBar.Horizontal" .../> Ifyouwillusetheprogressbartoshowrealprogress,youmustusethehorizontalbar.YoucanthenincrementtheprogresswithincrementProgressBy()orsetProgress().Bydefault,theprogressbarisfullwhenitreaches100.Ifnecessary,youcanadjustthemaximumvalue(thevalueforafullbar)usingtheandroid: maxattribute.Otherattributesavailablearelistedbelow. AnothercommonstyletoapplytotheprogressbarisWidget.ProgressBar.Small,whichshowsasmallerversionofthespinningwheel—usefulwhenwaitingforcontenttoload.Forexample,youcaninsertthiskindofprogressbarintoyourdefaultlayoutforaviewthatwillbepopulatedbysomecontentfetchedfromtheInternet—thespinningwheelappearsimmediatelyandwhenyourapplicationreceivesthecontent,itreplacestheprogressbarwiththeloadedcontent.Forexample: android: orientation="horizontal" ...> android: layout_width="wrap_content" android: layout_height="wrap_content" style="@android: style/Widget.ProgressBar.Small" android: layout_marginRight="5dp"/> android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/loading"/> Otherprogressbarstylesprovidedbythesysteminclude: Widget.ProgressBar.Horizontal Widget.ProgressBar.Small Widget.ProgressBar.Large Widget.ProgressBar.Inverse Widget.ProgressBar.Small.Inverse Widget.ProgressBar.Large.Inverse The"inverse"stylesprovideaninversecolorschemeforthespinner,whichmaybenecessaryifyourapplicationusesalightcoloredtheme(awhitebackground). XMLattributes SeeProgressBarAttributes,ViewAttributes Summary XMLAttributes AttributeNameRelatedMethodDescription android: animationResolutionTimeoutbetweenframesofanimationinmilliseconds Mustbeanintegervalue,suchas"100". android: indeterminateAllowstoenabletheindeterminatemode. android: indeterminateBehaviorDefineshowtheindeterminatemodeshouldbehavewhentheprogressreachesmax. android: indeterminateDrawableDrawableusedfortheindeterminatemode. android: indeterminateDurationDurationoftheindeterminateanimation. android: indeterminateOnlyRestrictstoONLYindeterminatemode(state-keepingprogressmodewillnotwork). android: indeterminateTintsetIndeterminateTintList(ColorStateList)Tinttoapplytotheindeterminateprogressindicator. android: indeterminateTintModesetIndeterminateTintMode(PorterDuff.Mode)Blendingmodeusedtoapplytheindeterminateprogressindicatortint. android: interpolator android: maxDefinesthemaximumvaluetheprogresscantake. android: maxHeightAnoptionalargumenttosupplyamaximumheightforthisview. android: maxWidthAnoptionalargumenttosupplyamaximumwidthforthisview. android: minHeight android: minWidth android: mirrorForRtlDefinesiftheassociateddrawablesneedtobemirroredwheninRTLmode. android: progressDefinesthedefaultprogressvalue,between0andmax. android: progressBackgroundTintsetProgressBackgroundTintList(ColorStateList)Tinttoapplytotheprogressindicatorbackground. android: progressBackgroundTintModesetProgressBackgroundTintMode(PorterDuff.Mode)Blendingmodeusedtoapplytheprogressindicatorbackgroundtint. android: progressDrawableDrawableusedfortheprogressmode. android: progressTintsetProgressTintList(ColorStateList)Tinttoapplytotheprogressindicator. android: progressTintModesetProgressTintMode(PorterDuff.Mode)Blendingmodeusedtoapplytheprogressindicatortint. android: secondaryProgressDefinesthesecondaryprogressvalue,between0andmax. android: secondaryProgressTintsetSecondaryProgressTintList(ColorStateList)Tinttoapplytothesecondaryprogressindicator. android: secondaryProgressTintModesetSecondaryProgressTintMode(PorterDuff.Mode)Blendingmodeusedtoapplythesecondaryprogressindicatortint. [Expand] InheritedXMLAttributes Fromclassandroid.view.View [Expand] InheritedConstants Fromclassandroid.view.View [Expand] InheritedFields Fromclassandroid.view.View PublicConstructors ProgressBar(Contextcontext) Createanewprogressbarwithrange0...100andinitialprogressof0. ProgressBar(Contextcontext,AttributeSetattrs) ProgressBar(Contextcontext,AttributeSetattrs,intdefStyleAttr) ProgressBar(Contextcontext,AttributeSetattrs,intdefStyleAttr,intdefStyleRes) PublicMethods voiddrawableHotspotChanged(floatx,floaty) Thisfunctioniscalledwhenevertheviewhotspotchangesandneedstobepropagatedtodrawablesorchildviewsmanagedbytheview. CharSequencegetAccessibilityClassName() Returntheclassnameofthisobjecttobeusedforaccessibilitypurposes. DrawablegetIndeterminateDrawable() Getthedrawableusedtodrawtheprogressbarinindeterminatemode. ColorStateListgetIndeterminateTintList() PorterDuff.ModegetIndeterminateTintMode() Returnstheblendingmodeusedtoapplythetinttotheindeterminatedrawable,ifspecified. InterpolatorgetInterpolator() Getstheaccelerationcurvetypefortheindeterminateanimation. synchronizedintgetMax() Returntheupperlimitofthisprogressbar'srange. synchronizedintgetProgress() Gettheprogressbar'scurrentlevelofprogress. ColorStateListgetProgressBackgroundTintList() Returnsthetintappliedtotheprogressbackground,ifspecified. PorterDuff.ModegetProgressBackgroundTintMode() DrawablegetProgressDrawable() Getthedrawableusedtodrawtheprogressbarinprogressmode. ColorStateListgetProgressTintList() Returnsthetintappliedtotheprogressdrawable,ifspecified. PorterDuff.ModegetProgressTintMode() Returnstheblendingmodeusedtoapplythetinttotheprogressdrawable,ifspecified. synchronizedintgetSecondaryProgress() Gettheprogressbar'scurrentlevelofsecondaryprogress. ColorStateListgetSecondaryProgressTintList() Returnsthetintappliedtothesecondaryprogressdrawable,ifspecified. PorterDuff.ModegetSecondaryProgressTintMode() Returnstheblendingmodeusedtoapplythetinttothesecondaryprogressdrawable,ifspecified. synchronizedfinalvoidincrementProgressBy(intdiff) Increasetheprogressbar'sprogressbythespecifiedamount. synchronizedfinalvoidincrementSecondaryProgressBy(intdiff) Increasetheprogressbar'ssecondaryprogressbythespecifiedamount. voidinvalidateDrawable(Drawabledr) InvalidatesthespecifiedDrawable. synchronizedbooleanisIndeterminate() Indicatewhetherthisprogressbarisinindeterminatemode. voidjumpDrawablesToCurrentState() CallDrawable.jumpToCurrentState()onallDrawableobjectsassociatedwiththisview. voidonRestoreInstanceState(Parcelablestate) Hookallowingaviewtore-applyarepresentationofitsinternalstatethathadpreviouslybeengeneratedbyonSaveInstanceState(). ParcelableonSaveInstanceState() Hookallowingaviewtogeneratearepresentationofitsinternalstatethatcanlaterbeusedtocreateanewinstancewiththatsamestate. voidpostInvalidate() Causeaninvalidatetohappenonasubsequentcyclethroughtheeventloop. synchronizedvoidsetIndeterminate(booleanindeterminate) Changetheindeterminatemodeforthisprogressbar. voidsetIndeterminateDrawable(Drawabled) Definethedrawableusedtodrawtheprogressbarinindeterminatemode. voidsetIndeterminateDrawableTiled(Drawabled) Definethetileabledrawableusedtodrawtheprogressbarinindeterminatemode. voidsetIndeterminateTintList(ColorStateListtint) Appliesatinttotheindeterminatedrawable. voidsetIndeterminateTintMode(PorterDuff.ModetintMode) Specifiestheblendingmodeu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ProgressBar 进度条