ANDROID_MARS学习笔记_S01_011ProgressBar

文档是这样来设置样式

 

 <ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Small"
         android:layout_marginRight="5dp" />

 

 

 

1.xml

<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/firstProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal" />
    
    <Button 
        android:id="@+id/firstButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstProgressBar"
        android:text="增加第一进度"/>
    
    <Button 
        android:id="@+id/secondButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstButton"
        android:text="增加第二进度"/>

</RelativeLayout>

 

2.java

 1 package com.marschen.s01_e17_progressbar;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.view.Menu;
 6 import android.view.View;
 7 import android.view.View.OnClickListener;
 8 import android.widget.Button;
 9 import android.widget.ProgressBar;
10 
11 public class MainActivity extends Activity {
12 
13     private ProgressBar progressBar;
14     private Button firstButton;
15     private Button secondButton;
16     @Override
17     protected void onCreate(Bundle savedInstanceState) {
18         super.onCreate(savedInstanceState);
19         setContentView(R.layout.activity_main);
20         
21         progressBar = (ProgressBar)findViewById(R.id.firstProgressBar);
22         firstButton = (Button)findViewById(R.id.firstButton);
23         secondButton = (Button)findViewById(R.id.secondButton);
24         
25         progressBar.setMax(100);
26         
27         firstButton.setOnClickListener(new FirstListener());
28         secondButton.setOnClickListener(new SecondListener());
29         
30     }
31     
32     class FirstListener implements OnClickListener{
33 
34         @Override
35         public void onClick(View v) {
36             progressBar.incrementProgressBy(10);
37         }
38         
39     }
40     
41     class SecondListener implements OnClickListener{
42 
43         @Override
44         public void onClick(View v) {
45             progressBar.incrementSecondaryProgressBy(20);
46         }
47         
48     }
49 
50     @Override
51     public boolean onCreateOptionsMenu(Menu menu) {
52         // Inflate the menu; this adds items to the action bar if it is present.
53         getMenuInflater().inflate(R.menu.main, menu);
54         return true;
55     }
56 
57 }

 

posted @ 2016-02-12 13:03  shamgod  阅读(158)  评论(0编辑  收藏  举报
haha