Sunday, 6 May 2018

How to add Progress bar until image not Showing in Android

 - In Java file add following code
     //To set value in components
          if (image != null && !image.isEmpty()) {
          Picasso.with(ProfileActivity.this).load(AppConstant.TAG_Image_Base_Path + image)
          .into(image_student, new ImageLoadedCallback(progressBar) {
            @Override
            public void onSuccess() {
             if (progressBar != null) {
                 progressBar.setVisibility(View.GONE);
                  }
                }
               });
             } else {
                image_student.setImageResource(R.mipmap.ic_launcher);
             }

  public class ImageLoadedCallback implements com.squareup.picasso.Callback {
        ProgressBar progressBar;
        public ImageLoadedCallback(ProgressBar progBar) {
            progressBar = progBar;
        }

        @Override
        public void onSuccess() {
        }

        @Override
        public void onError() {
        }
    }

- In main.xml Add Following Code
 
    <RelativeLayout
     android:layout_width="65dp"
     android:gravity="center"
     android:layout_gravity="bottom"
     android:layout_height="65dp">

     <ImageView
      android:id="@+id/image_student"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />

     <ProgressBar
      android:id="@+id/progressBar"
      style="?android:attr/progressBarStyleSmall"
      android:layout_width="30dp"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:layout_height="30dp"
      android:visibility="gone" />

     </RelativeLayout>

No comments:

Post a Comment