Android: Show progress circle like Google does in their apps - android

I'm using an AsyncTask to download Images for my Listview, because I dont want the download of the Images to block my UI-Thread. While the images are being loaded, I want to show an animated progress circle in the spot, where the image will be.
But I cant find an Image of the progress circle. What is the Ressource-Id? Or is there any other way? Does someone has a link to this image?

Look at the progress bar. It can work (and it does by default, AFAIR) in indeterminate mode, which means it shows a rotating circle, like the one you are asking for. I know this is not an image, but what you can do, is to place a FrameLayout instead of the image, with progress bar as the only child. Then, once the loading of the images finishes, remove the progress bar and add the image.

Define this a global variable ProgressDialog pd;
Just before launche the AsyncTask do:
pd = ProgressDialog.show(CurrentClassName.this,"This is the title","This is the detail text",true,false,null);
When its done onPostExecute just call pd.dismiss();
For more detail look at : ProgressDialog
You will have to take special considerations for it to work when you rotate the device while the dialog is up.

This is an example of a layout file for intro activity with an image and circle progress bar:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/intro_description"
android:scaleType="fitXY"
android:src="#drawable/intro" />
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:visibility="visible" />
</FrameLayout>

You want an indeterminate ProgressBar. Take a look at developer's website -
ProgressBar

Related

How to make blured activity when loading gif appears?

I have an upload activity and a loading animation. I want to make activity blured(or lock, idk) while loading animation waiting for response about uploading. Something like I press upload button, animation appears, activity is locked, then app get response about uploading and animation is gone and activity become unblured. Is there a way to make it ?
Thanks in advance!
Use alpha and make the layout clickable so that other view remains lock behind this. Show/hide RelativeLayout to show/hide progress.
<RelativeLayout
android:alpha=".5"
android:clickable="true"
android:background="#android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>

Add Spinning progress for ImageView in Android

I have an ImageView in which i want to show ProgressBar while loading the image from URL. To load image i am using VolleyPlus library. Here is the code to load image:
DiskLruBasedCache.ImageCacheParams cacheParams = new DiskLruBasedCache.ImageCacheParams(getApplicationContext(), "CacheDirectory");
cacheParams.setMemCacheSizePercent(0.5f);
SimpleImageLoader mImageFetcher = new SimpleImageLoader(getApplicationContext(), R.drawable.progress, cacheParams);
mImageFetcher.get(image_url, imgView);
Now my problem is Can i make drawable to make ProgressBar (R.drawable.progress) within ImageView.
You use setDefaultImageResId to an image to show during loading and if failed but you will not be able to use a view though. You can however use FrameLayout and ProgressBar behind NetworkImageView to show spinning progress while loading.
In case of successful download you do not have to do anything thing because Android should draw the progress view because it is hidden, in case of failure you will have to take it off.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.android.volley.toolbox.NetworkImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
</FrameLayout>

How to PROPERLY show ProgressBar for a Webview while loading

I wan't to indicate that my webview is loading in some way. Using the Progressbar seems like a good solution but I am not certain how to properly do this.
By Progressbar I mean a spinning thingie in Android.
This is what I know by now and what I have tried:
I know about onPageStarted(...) and onPageFinished(...) callbacks which you define inside the WebViewClient and then hide or show Progressbar based on calls to those methods. BUT this approach is creating many problems with the HTML page inside the webview. For example when I hide Progressbar HTML elements resize and than go back to their original sizes for a brief moment. This looks really ugly and I don't know why this is happening. I tried putting my Progressbar and webview inside Frame and Relative layout (in order to have the progress cantered) and with both of these I get the above problem. HTML page loading is Javascript heavy since there is http://cubiq.org/iscroll-4 library on it but I doubt it's the problem with the library since the same page loads without strange behaviours when opened in Browser app on the phone.
My main problem is that I don't know how to define a layout containing my Progressbar and webview and avoid strange zoom in/out jumps. That is why I am asking how should one show progress bar correctly over a webview.
EDIT:
This is one of the layouts I tried:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
It's more or less similar with relative layout but I use centerInPerent=true on both axes for the ProgressBar
There's an efficient way to show progress in an activity. If you are using ActionBar, then
you can set an INDETERMINATE progressbar (the spinning one), or a horizontal progressbar (as seen on web browsers like Chrome). To do this you have to set the Window Feature to appropriate values like:
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
OR
requestWindowFeature(Window.FEATURE_PROGRESS);
To set the progress value, do this:
setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
Then call setProgress(int) whenever you want to change the progress value.
You can controll the visibility of the progressbar using
setProgressBarIndeterminateVisibility(true); //sets it to visible
AND
setProgressBarIndeterminateVisibility(false); //hides the progressbar
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view.
I would use a RelativeLayout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:centerInParent="true" />
</RelativeLayout>
This should work...

ProgressBar at the bottom of gridview

I have a GridView which shows a grid of 15 Views for the first time. Then, on click of a button, I add 5 more grid views. So, my question is: How to add a ProgressBar at the bottom of a page, when those 5 Views are loading ? Like a spinner loading and the 5 Views get updated.
Hi i have a tab host tabwidget for tabs and gridview inside framlayout..now if i want the progressbar then should i need to inclue this linearlayout after frame layout or inside frame laoyout?
Add this below your GridView in the XML.
<LinearLayout
android:id="#+id/linlaProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ProgressBar
style="#style/Spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" />
</LinearLayout>
And in your Activity, where you are loading the data (assuming, it is an AsyncTask), in your onPreExecute() show it:
#Override
protected void onPreExecute() {
// SHOW THE BOTTOM PROGRESS BAR (SPINNER) WHILE LOADING MORE PHOTOS
linlaProgressBar.setVisibility(View.VISIBLE);
}
And in the onPostExecute(), hide it:
#Override
protected void onPostExecute() {
// SHOW THE BOTTOM PROGRESS BAR (SPINNER) WHILE LOADING MORE PHOTOS
linlaProgressBar.setVisibility(View.GONE);
}
If you are not using an AsyncTask, then set the visibility to View.VISIBLE at the start of the method where you start downloading the data and set it to View.GONE either after or just before you set the Adapter.
EDIT: Adding additional info.
Couple of things.
You are downloading data off the Internet for which, I would recommend switching to AsycnTask instead of using a conventional () Method.
Check out my answer a few days ago on a similar question here: https://stackoverflow.com/a/13265776/450534
In that answer, you will find a complete solution that will suit your exact needs. Well, almost entirely anyway. You may have to make a few modifications and adapt to a few things yourself. But by and large, it will answer all your questions. I use it in my apps and they function as you say, the Google Play loading text at the bottom. And it really is complete. :-)
You need to create custom view for that and inflate it and add as bottom view in gridview
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button android:text="Load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
<ProgressBar
android:layout_width="25.0dip"
android:layout_height="25.0dip"
android:layout_centerInParent="true"
android:visibility="gone"
/>
</RelativeLayout>
now inflate this view and show the progressbar at bottom of gridview
You can set button as bottom with this when you click just visible the progressbar
Just add a ProgressBar in your layout, set its visibility to VISIBLE or GONE whenever you want to show/hide it.
Add a in the xml of GridView and set its property "alignParentRight = true" and "visibility = invisible" . In your activity , use Async task class and on its preExectue method set set its visibility to visible
pb.setVisibility(View.VISIBLE);
In doInBackground method load your images and finally in onPostExecute method make this progress bar invisible.
pb.setVisibility(View.INVISIBLE);
execute this async task class on click of load button.
This is an easy tutorial for understanding asyncTask
http://androidresearch.wordpress.com/2012/03/17/understanding-asynctask-once-and-forever/
Or threads can be used instead of async task.

Custom progress dialog

How would I do a custom "loading" dialog during an AsyncTask like the one in the Bank of America app, for instance? See:
I basically don't want the popup ProgressDialog but instead one that is embedded into the layout.
It's not a ProgressDialog. It's just a ProgressBar. Put it on your layout and make it visible when it's necessary.
That's a ProgressBar view that can be added to any layout:
<ProgressBar
android:indeterminate="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>

Categories

Resources