以下实现的是点击独立的按钮,进度条会动,达到100%时进度条会消失的效果。

     网上搜到的都是按钮和进度条合二为一的效果,我就不写了。:)

 

实现效果预览

     

     XML部分代码

 1 <!-- 进度条 -->
 2     <ProgressBar        
 3         android:id="@+id/progressBar1"
 4         style="@android:style/Widget.ProgressBar.Horizontal"
 5         android:layout_width="match_parent"
 6         android:layout_height="wrap_content"
 7         android:max="100"/>
 8     
 9     <!-- 按钮 -->
10     <Button 
11         android:id="@+id/pc"
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:text="点击前进"/>

 

     java部分代码

 1 public class other extends Activity{
 2     
 3     
 4     private ProgressBar horizonP;
 5     
 6     
 7     private Button pc;
 8 
 9 
10     @Override
11     protected void onCreate(Bundle savedInstanceState) {
12         // TODO Auto-generated method stub
13         super.onCreate(savedInstanceState);
14         setContentView(R.layout.other);
15         
16         
17         horizonP = (ProgressBar)findViewById(R.id.progressBar1);
18         
19         
20         pc=(Button)findViewById(R.id.pc);
21         pc.setOnClickListener(new OnClickListener() {
22             
23             @Override
24         public void onClick(View v) {
25                 
26             int progress = horizonP.getProgress()+10;
27                 horizonP.setProgress(progress);
28                 
29                 if(progress >= horizonP.getMax()){
30                     
31                     horizonP.setVisibility(View.GONE);
32                     
33                 }
34                 
35                 
36         }
37     });
38           
39         
40     }
41         
42     
43 }

 

有帮到你的话,点个推荐吧~