-2

I have a dummy RelativelayoutView with progress bar.

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/progressbar">
            <ProgressBar
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/progressBar" />
    </RelativeLayout>

When my app starts I need this RelativelayoutView to appear for 5 seconds and should diappear with or without animation.

Simon
  • 461
  • 1
  • 5
  • 23
  • Possible duplicate of [Set visibility of progress bar gone on completion of image loading using Glide library](http://stackoverflow.com/questions/26054420/set-visibility-of-progress-bar-gone-on-completion-of-image-loading-using-glide-l) – Ravindra Kushwaha Feb 10 '17 at 13:24

1 Answers1

1

I'm not sure I understood your question, but I'd suggest you to write something like this in your activity:

private Handler mHandler;

@Override
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.your_layout);

     mHandler = new Handler(Looper.getMainLooper());
     mHandler.postDelayed(new Runnable() {
          public void run() {
               // hide your progress bar
               findViewById(R.id.progressBar).setVisibility(View.GONE);
               // or finish this activity and start a new one
               startActivity(new Intent(MyActivity.this, MySecondActivity.class));
          }
     }, 5000);
}

@Override
public void onDestroy() {
     super.onDestroy();
     mHandler.removeCallbacks(null);
}

And I think you should add the android:indeterminate="true" attribute to your progress bar.

Hope it helps. Cheers.

andrea.rinaldi
  • 1,167
  • 1
  • 13
  • 33
  • Thank you sir... perfect.. this is what I needed... Can i do the same by creating a android resource file for progress bar so that i can hide the title bar?.. – Simon Feb 10 '17 at 14:00
  • if you want to hide the title bar of the activity you have to set the theme attribute in the manifest for the specific activity: 'android:theme="@style/Theme.AppCompat.Light.NoActionBar"'.. if the previous answer is correct please mark my post as the right one! – andrea.rinaldi Feb 10 '17 at 14:41
  • If I make 'android:theme="@style/Theme.AppCompat.Light.NoActionBar"' change then whole of my layout will be with no action bar... I just need the progress bar layout to be with noAction bar... thank you sir... – Simon Feb 10 '17 at 14:52