how to show progress bar(circle) in an activity having a listview before loading the listview with data

后端 未结 12 2433
忘掉有多难
忘掉有多难 2020-11-28 00:18

I have a ListView in my second activity.OnItemClick of it I called a webservice and trying to fetch data. And after that I am moving to third activ

12条回答
  •  执念已碎
    2020-11-28 01:08

    Process Bar:

    Dependency:

         implementation 'com.github.castorflex.smoothprogressbar:library:1.0.0'
    

    XML:

         
    

    In Res->color

          #ff1635
          
              @color/pocket_color_1
          
    
          #00ff00
          
              @color/pocket_color_stop
          
    

    In Main:

          public class MainActivity extends AppCompatActivity{
            SmoothProgressBar smoothProgressBar;
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              smoothProgressBar=findViewById(R.id.myProcessbar);
              showProcessBar();
              stopAnimation();    // call when required to stop process
            }
    
            public void showProcessBar(){
              smoothProgressBar.setVisibility(View.VISIBLE);
              smoothProgressBar.setIndeterminateDrawable(new SmoothProgressDrawable.Builder(getApplicationContext())
                .interpolator(new AccelerateInterpolator())
                .progressiveStart(true)
                .progressiveStopSpeed(1000)
                .build());
              smoothProgressBar.setSmoothProgressDrawableBackgroundDrawable(
              SmoothProgressBarUtils.generateDrawableWithColors(
                        getResources().getIntArray(R.array.pocket_background_colors),
                        ((SmoothProgressDrawable)  smoothProgressBar.getIndeterminateDrawable()).getStrokeWidth()));
            }
    
            public void stopAnimation(){
              smoothProgressBar.setSmoothProgressDrawableBackgroundDrawable(
              SmoothProgressBarUtils.generateDrawableWithColors(
                        getResources().getIntArray(R.array.pocket_background_stop),
                        ((SmoothProgressDrawable)  smoothProgressBar.getIndeterminateDrawable()).getStrokeWidth()));
              smoothProgressBar.progressiveStop();
              Handler handler=new Handler();
              handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                   smoothProgressBar.animate().alpha(0.0f).setDuration(6000).translationY(1000);
                   smoothProgressBar.setVisibility(View.GONE);
                }
              },1000);
    }
    
          }
    

提交回复
热议问题