Android之进度条

ProgressBar有垂直风格与水平风格之分

SeekBarRatingBarProgressBar的子类

XML部分:

<!--如果不设置style风格,则默认为垂直风格的进度条-->

<ProgressBar

android:id="@+id/progressbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:max="150"

android:progress="75"

android:secondaryProgress="100"

style="?android:attr/progressBarStyleHorizontal"

/>

<!―设置进度条、当前进度条、第二进度条-->

<SeekBar

android:id="@+id/seekBar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/progressbar"

android:max="100"

android:progress="50"

android:secondaryProgress="60"

/>

<!--numstars星星个数stepSize每次跨的长度-->

<RatingBar

android:id="@+id/ratingBar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:numStars="5"

android:stepSize="1"

android:layout_below="@id/seekBar"

/>

Java部分:

publicclassMainActivityextendsActivity{

privateProgressBarprogressBar;

privateSeekBarseekBar;

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

progressBar=(ProgressBar)findViewById(R.id.progressbar);

//判断属于哪种进度条,是水平的还是垂直的风格

booleanb=progressBar.isIndeterminate();

//设置第一进度条与第二进度条每次增加的值

progressBar.incrementProgressBy(15);

progressBar.incrementSecondaryProgressBy(20);

SeekBarListenerlistener=newSeekBarListener();

seekBar.setOnSeekBarChangeListener(listener);

}

classSeekBarListenerimplementsOnSeekBarChangeListener{

//progress当前SeekBar的进度

@Override

publicvoidonProgressChanged(SeekBarseekBar,intprogress,

booleanfromUser){

//TODOAuto-generatedmethodstub

System.out.println("progress"+fromUser);

}

@Override

publicvoidonStartTrackingTouch(SeekBarseekBar){

//TODOAuto-generatedmethodstub

System.out.println("start");

}

@Override

publicvoidonStopTrackingTouch(SeekBarseekBar){

//TODOAuto-generatedmethodstub

System.out.println("stop");

}

}

更多相关文章

  1. Android 水平的ListView
  2. android view子类的构建
  3. Android中自定义水平的ProgressBar
  4. 1. 2 Textview 及其子类

随机推荐

  1. android实现静默安装demo
  2. Android,机器狗应用
  3. Android Layout Tricks #3: Optimize by
  4. android 全屏幕
  5. RSA 签名
  6. android利用均衡器显示跳动频谱
  7. Android Clipping
  8. android监听键盘弹出or隐藏方法
  9. android实现拨打电话
  10. Android 支付宝支付密码输入界面