美文网首页
Mars_ProgressBar

Mars_ProgressBar

作者: pengtuanyuan | 来源:发表于2016-09-25 12:52 被阅读0次
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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:orientation="vertical"
        tools:context="com.example.pengtuanyuan.progressbardemo.MainActivity">
    
        <TextView
            android:id="@+id/textView1"
    
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/Hello"/>
    
        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:visibility="gone"/>
    
        <ProgressBar
            android:id="@+id/progressBar2"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:max="100"
            android:visibility="gone"/>
        <Button
            android:id="@+id/myButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Begin"/>
    
    </LinearLayout>
    ---------------------------------------------------------
    
    package com.example.pengtuanyuan.progressbardemo;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ProgressBar;
    
    public class MainActivity extends AppCompatActivity {
        private ProgressBar firstBar=null;
        private ProgressBar secondBar=null;
        private Button button=null;
        private int i=0;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            firstBar=(ProgressBar)findViewById(R.id.progressBar1);
            secondBar=(ProgressBar)findViewById(R.id.progressBar2);
            button=(Button)findViewById(R.id.myButton);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(i==0){
                        firstBar.setVisibility(View.VISIBLE);
                        secondBar.setVisibility(View.VISIBLE);
                    }
                    else if (i<firstBar.getMax()){
                        firstBar.setProgress(i);
                        firstBar.setSecondaryProgress(i+10);
                    }else {
                        firstBar.setVisibility(View.GONE);
                        secondBar.setVisibility(View.GONE);
                    }
                    i=i+10;
                }
            });
        }
    }
    
    
    2.png

    相关文章

      网友评论

          本文标题:Mars_ProgressBar

          本文链接:https://www.haomeiwen.com/subject/tkdfyttx.html