2016-07-05 3 views
0

정적으로 말하자면, 최대 값이 100 일 수있는 데이터가 20 개 있습니다. 진행률을 지정하고 싶습니다. 그런 다음 진행 탭을 열면 호출 될 활동이 필요합니다. 진도를로드하고 100에서 20에 도달하면 멈 춥니 다.안드로이드에서 정적 진행 표시 줄 만들기

마침내 보일 것입니다.

Progress. 
++++---------------- 
Progress1. 
+++++++++++--------- 
Progress3. 
+++++++------------- 

내가 봤와 정확히 내 요구 사항을 알려줍니다이 지프를 얻었다. 나는 시도하고 얻을 수있는 무엇 GIF

은 다음과 같습니다

활동

public class test extends Activity { 
    private ProgressBar progressBar; 
    private int progressStatus = 0, CurrValue=20; 
    private TextView textView; 
    private Handler handler = new Handler(); 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_loop); 
     progressBar = (ProgressBar) findViewById(R.id.progressBar1); 
     textView = (TextView) findViewById(R.id.textView1); 
     progressBar.setScaleY(3f); 
     // Start long running operation in a background thread 
     Progress(); 
    } 
    public void Progress(){ 
     new Thread(new Runnable() { 
      public void run() { 
       while (progressStatus < CurrValue) { 
        progressStatus += 1; 
        // Update the progress bar and display the 
        //current value in the text view 
        handler.post(new Runnable() { 
         public void run() { 
          progressBar.setProgress(progressStatus); 
          textView.setText(progressStatus+"/"+progressBar.getMax()); 
         } 
        }); 
        try { 
         // Sleep for 200 milliseconds. 
         //Just to display the progress slowly 
         Thread.sleep(100); 
        } catch (InterruptedException e) { 
         e.printStackTrace(); 
        } 
       } 
      } 
     }).start(); 
    } 
} 

레이아웃

그것에는 내가 보여주고 싶은 텍스트 뷰 및 ProgressBar를

애니메이션이있는 여러 개의 진행률 표시 줄 위의 GIF 링크를 클릭하십시오.

답변

1

는 여기에 아이디어 :

  1. 가 ProgressUpdater 클래스를 만듭니다. 생성자에서 ProgressBar, 진행률을 모니터 할 변수 및 최대 값 (0은 최소값 또는 최소값이 0에서 최대 값이 아닐 경우)을 사용합니다.
  2. 변수를 확인하고 진행률을 계산하거나 ProgressBar를 업데이트하도록 호출하는 UpdateProgress() 메서드가 있습니다.
  3. 활동에는 각 ProgressBar와 함께 onCreate에서 초기화되는 ProgressUpdaters 배열이 있습니다.
  4. Progress()는 ProgressUpdaters의 배열을 반복하고 각각에 대해 UpdateProgress()를 호출합니다. 여러 값을 처리하거나 일부 리스너를 사용하고 ProgressUpdater의 UpdateProgress() 메서드를 호출하려면 Progress()를 약간 변경해야합니다.

어떻게 그런 소리를합니까?

+0

내가 해냈어. 그리고 그 일. : D 고마워! – impossible

+0

@ArewegoodQ 멋진, 훌륭한 직장! – iheanyi