Android进度条简单练习实例

来源:互联网 发布:印度教 基督教 知乎 编辑:程序博客网 时间:2024/06/02 20:44


<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >    <ProgressBar         android:id="@+id/ProgressBar1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        style="?android:attr/progressBarStyleHorizontal"       />       <Button            android:id="@+id/button1"           android:layout_height="wrap_content"           android:layout_width="match_parent"           android:layout_below="@+id/ProgressBar1"           android:text="主进度增加10"/>       <Button           android:id="@+id/button2"           android:layout_height="wrap_content"           android:layout_width="match_parent"           android:layout_below="@id/button1"           android:text="第二进度增加20"/>        </RelativeLayout>

package com.example.progressbar_o1;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ProgressBar;public class MainActivity extends Activity {private ProgressBar progressBar1;private Button button1;private Button button2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);progressBar1 = (ProgressBar) findViewById(R.id.ProgressBar1);button1 = (Button) findViewById(R.id.button1);button2 = (Button) findViewById(R.id.button2);FirstClick  fist=new FirstClick();SenClick send=new SenClick();button1.setOnClickListener(fist);button2.setOnClickListener(send);/* * progressBar1.setMax(400); progressBar1.setProgress(300); * progressBar1.setSecondaryProgress(350); //判断是否垂直还是水平style true为垂直 * false为水平 boolean isfalg=progressBar1.isIndeterminate(); //主进度增加10 * progressBar1.incrementProgressBy(10); //第二进度增加10 * progressBar1.incrementSecondaryProgressBy(10); */}class FirstClick implements OnClickListener {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubprogressBar1.incrementProgressBy(10);}}class SenClick implements OnClickListener {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubprogressBar1.incrementSecondaryProgressBy(20);}}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}

Android当中的进度条
ProgressBar 有两种进度条  一种垂直(圆圈) 一种水平(水平线)


SeekBar 拖拽进度条(MP3播放的哪种)
RatingBar 三角形(类是酒店评分)
SeekBar、和RatingBar都是 ProgressBar类的子类


ProgressBar的style
水平风格:Horizontal
小风格:Small
反方向风格:Inverse
小反向的风格:Small.Inverse
大反向风格:Large.Inverse


进度条的主要属性
进度条最大值:max
当前进度:progress
次要进度的值:SecondaryProgress


原创粉丝点击