I added a ProgressBar to fragments in my application. I set it for the two main snippets (used as tabs) as follows:
ProgressBar in activity_main.xml :
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout>
Setting ProgressBar VISIBLE and GONE :
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1); spinner.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE);
This works without a problem. I tried adding another ProgressBar to another snippet that has a WebView :
ProgressBar in fragment_article.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="info.androidhive.slidingmenu.ArticleFragment$PlaceholderFragment" > <WebView android:id="@+id/webPage" android:layout_height="wrap_content" android:layout_width="wrap_content"/> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout>
Visibility setting:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1); spinner.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE);
The visibility setting is the same as the previous code, but for some reason this does not set the ProgressBar to GONE . Not sure what happened.
I tried using clearAnimation , as suggested here by Android, setVisbility does not work in RelativeLayout , but still nothing.
spinner.clearAnimation(); spinner.setVisibility(View.GONE);
android progress-bar android-fragments android-spinner
j.grima
source share