android学习笔记12(ProgressBar--进度条--初级学习)

MyProgressBar.java

package tk.progressbar;



import android.app.Activity; 

import android.os.Bundle; 

import android.view.Menu; 

import android.view.View; 

import android.view.View.OnClickListener; 

import android.widget.Button; 

import android.widget.ProgressBar;







public class MyProgressBar extends Activity {



    private ProgressBar firstBar=null; 

    private ProgressBar secondbBar=null; 

    private Button myButton=null; 

    private int i=0; 

    @Override 

    public void onCreate(Bundle savedInstanceState) { 

        super.onCreate(savedInstanceState); 

        setContentView(R.layout.progress_bar); 

        firstBar  =  (ProgressBar)findViewById(R.id.firstBar); 

        secondbBar = (ProgressBar)findViewById(R.id.secondBar); 

        myButton=(Button)findViewById(R.id.myButton); 

        myButton.setOnClickListener(new ButtonListener()); 

    } 

    class ButtonListener implements OnClickListener{



        @Override 

        public void onClick(View v) { 

            

            if(i==0){ 

                

                firstBar.setVisibility(View.VISIBLE); 

                secondbBar.setVisibility(View.VISIBLE); 

                firstBar.setProgress(i); 

                firstBar.setSecondaryProgress(i); 

            }else if(i<firstBar.getMax()){ 

                firstBar.setProgress(i); 

                firstBar.setSecondaryProgress(i 10); 

                secondbBar.setProgress(i); 

            }else{ 

                firstBar.setVisibility(View.GONE); 

                secondbBar.setVisibility(View.GONE); 

                i=-10; 

            } 

            i =10; 

        } 

        

    

    }



    @Override 

    public boolean onCreateOptionsMenu(Menu menu) { 

        getMenuInflater().inflate(R.menu.progress_bar, menu); 

        return true; 

    } 

}

progress_bar.xml

<?xml version= "1.0" encoding ="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:orientation= "vertical" 

    android:layout_width= "fill_parent" 

    android:layout_height= "fill_parent" 

    > 

        <TextView 

            android:id="@ id/textView1" 

            android:layout_width="fill_parent" 

            android:layout_height="wrap_content" 

            android:text="@string/hello" 

            /> 

        <ProgressBar 

            android:id="@ id/firstBar" 

            style="?android:attr/progressBarStyleHorizontal" 

            android:layout_width="200dp" 

            android:layout_height="wrap_content" 

            android:visibility="gone" 

            android:max="200" 

            /> 

        <ProgressBar 

            android:id="@ id/secondBar" 

            style="?android:attr/progressBarStyle" 

            android:layout_height="wrap_content" 

            android:layout_width="wrap_content" 

            android:visibility="gone" 

            /> 

        <Button 

            android:id="@ id/myButton" 

            android:layout_width="wrap_content" 

            android:layout_height="wrap_content" 

            android:text="begin" 

            /> 

                

</LinearLayout>

你可能感兴趣的:(ProgressBar)