rAndroid(11):进度条ProgressBar/SeekBar/RatingBar
来源:互联网 发布:sql语句拼接 单双引号 编辑:程序博客网 时间:2024/04/29 01:42
- Android中的进度条:
- 第一排的是ProgressBar,他们风格不同而已,第二排的三和四是ProgressBar的子类
- 在xml文件中设置ProgressBar的属性
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" ><ProgressBar android:id="@+id/progressBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="200" android:progress="100" android:secondaryProgress="150" style="?android:attr/progressBarStyleHorizontal" /><Button android:id="@+id/firstProgress_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="增加第一进度"></Button><Button android:id="@+id/secondProgress_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="增加第二进度"></Button></LinearLayout>
- 在代码中设置ProgressBar的属性
package com.borqs.firstpj;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.DatePicker;import android.widget.ProgressBar;import android.widget.TimePicker;import android.widget.TimePicker.OnTimeChangedListener;public class MainActivity extends ActionBarActivity { ProgressBar mProgressBar; Button mFirstProgress; Button mSecondProgress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mProgressBar = (ProgressBar)findViewById(R.id.progressBar); mFirstProgress = (Button)findViewById(R.id.firstProgress_btn); mSecondProgress = (Button)findViewById(R.id.secondProgress_btn); //设置进度条的最大值// mProgressBar.setMax(300); //设置进度条的当前进度 mProgressBar.setProgress(100); //设置进度条的第二进度值 mProgressBar.setSecondaryProgress(150); //是否是明确的方法,如果ProgressBar是明确的返回false,如果ProgressBar是不明确的返回ture boolean flag = mProgressBar.isIndeterminate(); ProgressButtonListener listener = new ProgressButtonListener(); mFirstProgress.setOnClickListener(listener); SecondProgressButtonListener l = new SecondProgressButtonListener(); mSecondProgress.setOnClickListener(l); } class ProgressButtonListener implements OnClickListener{ @Override public void onClick(View v) { mProgressBar.incrementProgressBy(10); } } class SecondProgressButtonListener implements OnClickListener{ @Override public void onClick(View v) { mProgressBar.incrementSecondaryProgressBy(20); } }}
SeekBar
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation= "horizontal"> <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/seekBar"/></LinearLayout>
public class MainActivity extends ActionBarActivity { private SeekBar mSeekBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSeekBar = (SeekBar)findViewById(R.id.seekBar); mSeekBar.setProgress(10); mSeekBar.setSecondaryProgress(50); onChangeListener listener = new onChangeListener(); mSeekBar.setOnSeekBarChangeListener(listener); } class onChangeListener implements OnSeekBarChangeListener{ /** * seekBar:指的是触发了监听器的Seekbar对象 * progress:当前进度 * fromUser:这次的变化是不是有用户引起的,如果是用户拖拽导致的SeekBar的变化是true */ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { System.out.println("seekBar:" + seekBar + ",progress:" + progress + ",fromUser:" + fromUser); } @Override public void onStartTrackingTouch(SeekBar seekBar) { System.out.println("start"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { System.out.println("stop"); } }
RatingBar
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation= "horizontal"> <RatingBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ratingBar"/> <Button android:id="@+id/btn" android:text="button" android:layout_width="match_parent" android:layout_height="wrap_content"/></LinearLayout>
private RatingBar mRatingBar; private Button mButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRatingBar = (RatingBar)findViewById(R.id.ratingBar); mButton = (Button)findViewById(R.id.btn); //总共5颗星 mRatingBar.setNumStars(5); //一次前进一颗星 mRatingBar.setStepSize(1); //监听步进变化 RatingBarChangedListener listener = new RatingBarChangedListener(); mRatingBar.setOnRatingBarChangeListener(listener); //测试button改变ratingbar步进值,fromUser为false. buttonClickChangedListener l = new buttonClickChangedListener(); mButton.setOnClickListener(l); } class RatingBarChangedListener implements OnRatingBarChangeListener{ @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { System.out.println("rating:" + rating + ",fromUser:" + fromUser); } } class buttonClickChangedListener implements OnClickListener{ @Override public void onClick(View v) { mRatingBar.setRating(mRatingBar.getRating() + 2.0f); } }
结果:当使用button改变ratingBar步进值时fromUser为false.
0 0
- rAndroid(11):进度条ProgressBar/SeekBar/RatingBar
- A08_(完善)ProgressBar & SeekBar & RatingBar 进度条的设置
- 【Android 初学】8、进度条(ProgressBar、SeekBar、RatingBar)
- 深入了解Android进度条——ProgressBar,SeekBar和RatingBar
- 深入了解Android进度条——ProgressBar,SeekBar和RatingBar
- android *** Layout 11 ProgressBar && RatingBar && SeekBar
- ProgressBar +SeekBar +RatingBar
- ProgressBar、SeekBar、RatingBar
- Android之ProgressBar、SeekBar、RatingBar
- Android--进度条--ProgressBar--SeekBar
- Android进度条(ProgressBar)拖动条(SeekBar)星级滑块(RatingBar)的例子
- Android中ProgressBar、RatingBar、SeekBar三种进度条的区别(十一)
- 第4组UI-ProgressBar及子类之ProgressBar(进度条)、SeekBar(拖动条)和RatingBar(星级评分条)
- android:progressBar/seekBar/ratingBar学习记录
- Android基础控件 - ProgressBar、SeekBar和RatingBar
- Progressbar、SeekBar进度条,滚动条
- Android UI系统控件进阶(二)—下拉列表控件Spinner,进度条ProgressBar,滑块控件SeekBar,评分控件RatingBar
- 第七章 —高级组件:拖动条seekBar、星级评分条RatingBar、进度条ProgressBar、滚动视图ScrollView
- poj 2139 Six Degrees of Cowvin Bacon 图论 Floyd最短路
- eclipse配置好SDK后启动报错
- 二分查找树
- Linux内核模块编程-proc文件系统
- 单例模式的七种写法
- rAndroid(11):进度条ProgressBar/SeekBar/RatingBar
- 常用的jsDoc
- Windows程序调试----第三部分 调试技术----第9章 内存调试
- Android 学习的好文章(以后有好的文章将不断更新链接)
- IOS单例模式(Singleton)
- Android Resource Types之Animation简介
- 同步/异步与阻塞/非阻塞的区别
- Torch学习——使用CUDA
- Android学习之碎片与活动之间的通信