Android进度条progressbar

xml文件代码部分

<ProgressBar 
    android:id="@+id/firstprobar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="200"
    android:progress="100"
    style="?android:attr/progressBarStyleHorizontal"
    />
<Button 
    android:id="@+id/bt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/firstprobar"
    android:text="前进"
    />
<Button 
    android:id="@+id/bt2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/bt1"
    android:text="后退"
    />

Mainactivity中代码

	private ProgressBar probar;
	private Button bt1;
	private Button bt2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        probar=(ProgressBar)findViewById(R.id.firstprobar);
        probar.setMax(100);
        /*probar.setProgress(20);
        boolean flag=probar.isIndeterminate();
        Toast.makeText(getApplicationContext(), flag+"", Toast.LENGTH_LONG).show();*/
        bt1=(Button)findViewById(R.id.bt1);
        bt2=(Button)findViewById(R.id.bt2);
        FirstLis f=new FirstLis();
        SecondLis s=new SecondLis();
        bt1.setOnClickListener(f);
        bt2.setOnClickListener(s);
    }

    class FirstLis implements OnClickListener{

		@Override
		public void onClick(View v) {
			probar.incrementProgressBy(10);
		}
    	
    	
    }
    class SecondLis implements OnClickListener{

		@Override
		public void onClick(View v) {
			probar.incrementProgressBy(-10);
		}
    	
    	
    }


本文出自 “Java大白的战地” 博客,请务必保留此出处http://8023java.blog.51cto.com/10117207/1660207

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。