【网学网提醒】:网学会员为您提供Android ProgressBar学习笔记(An-Beer工作室)参考,解决您在Android ProgressBar学习笔记(An-Beer工作室)学习中工作中的难题,参考学习。
AndroidProgressBar学习笔记
ProgressBar是Android的进度条。体验效果
源码
下载下面详细介绍ProgressBar一、说明在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度。一个进度条也可不确定其进度。在不确定模式下,进度条显示循环动画。这种模式常用于应用
程序使用任务的长度是未知的。二、XML重要属性android:progressBarStyle:默认进度条样式android:progressBarStyleHorizontal:水平样式
三、重要方法getMax():返回这个进度条的范围的上限getProgress():返回进度getSecondaryProgress():返回次要进度incrementProgressBy(intdiff):指定增加的进度isIndeterminate():指示进度条是否在不确定模式下setIndeterminate(booleanindeterminate):设置不确定模式下setVisibility(intv):设置该进度条是否可视四、重要事件onSizeChanged(intw,inth,intoldw,intoldh):当进度值改变时引发此事件五、实例1.布局文件
2.Java代码
packagewjq.WidgetDemo;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.view.Window;importandroid.widget.Button;importandroid.widget.ProgressBar;publicclassProgressBarDemoextendsActivity{/*(non-Javadoc)*@seeandroid.app.Activity#on
Create(android.os.Bundle)*/@OverrideprotectedvoidonCreate(BundlesavedInstanceState){//TODOAuto-generatedmethodstubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_PROGRESS);setContentView(R.layout.probarpage);setProgressBarVisibility(true);finalProgressBarprogressHorizontal=(ProgressBar)findViewById(R.id.progress_horizontal);setProgress(progressHorizontal.getProgress()*100);setSecondaryProgress(progressHorizontal.getSecondaryProgress()*100);Buttonbutton=(Button)findViewById(R.id.increase);button.setOnClickListener(newButton.OnClickListener(){publicvoidonClick(Viewv){progressHorizontal.incrementProgressBy(1);//Titleprogressisinrange0..10000setProgress(100*progressHorizontal.getProgress());}});button=(Button)findViewById(R.id.decrease);button.setOnClickListener(newButton.OnClickListener(){publicvoidonClick(Viewv){progressHorizontal.incrementProgressBy(-1);//Titleprogressisinrange0..10000setProgress(100*progressHorizontal.getProgress());}});
button=(Button)findViewById(R.id.increase_secondary);button.setOnClickListener(newButton.OnClickListener(){publicvoidonClick(Viewv){progressHorizontal.incrementSecondaryProgressBy(1);//Titleprogressisinrange0..10000setSecondaryProgress(100*progressHorizontal.getSecondaryProgress());}});button=(Button)findViewById(R.id.decrease_secondary);button.setOnClickListener(newButton.OnClickListener(){publicvoidonClick(Viewv){progressHorizontal.incrementSecondaryProgressBy(-1);//Titleprogressisinrange0..10000setSecondaryProgress(100*progressHorizontal.getSecondaryProgress());}});}}