Android之进度条ProgressBar

来源:互联网 发布:阿里云域名续费优惠 编辑:程序博客网 时间:2024/03/29 07:05

简单的在线播放中的缓存刻度和播放刻度的实现

布局

<!--注意设置其中的样式style    android:progressDrawable="@drawable/progress_bar"    上面这句可以重置样式,对其中的样式进行修改,再drawable下的xml中    最大值,第一进度条,第二进度条    -->    <ProgressBar        android:layout_width="match_parent"        android:layout_height="wrap_content"        style="@android:style/Widget.ProgressBar.Horizontal"        android:id="@+id/progressBar"        android:max="100"        android:progress="50"        android:secondaryProgress="80"         />

activity

public class ProgressActivity extends AppCompatActivity implements View.OnClickListener {    private ProgressBar progressBar;    private Button button1,button2,button3;    private TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_progress);        progressBar=(ProgressBar)findViewById(R.id.progressBar);        button1=(Button)findViewById(R.id.add);        button2=(Button)findViewById(R.id.reduce);        button3=(Button)findViewById(R.id.reset);        button1.setOnClickListener(this);        button2.setOnClickListener(this);        button3.setOnClickListener(this);    }    @Override    public void onClick(View v){        switch(v.getId()){            case R.id.add:                /**                 *  第一进度条,第二进度条,分别增加10,在布局文件中设置的最大值为100                 *  这里的第一进度条可以理解为播放的位置                 *  第二进度条可以理解为已经缓存的位置                 */                progressBar.incrementProgressBy(10);                progressBar.incrementSecondaryProgressBy(10);                break;            case R.id.reduce:                progressBar.incrementProgressBy(-10);                progressBar.incrementSecondaryProgressBy(-10);                break;        }    }}


0 0