I've been adding a ProgressBar
to the fragments in my app. I've set it up to the two main fragments (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 any problems. I've tried to add another ProgressBar
to another fragment which 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>
Setting Visibility:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
Setting the visibility the same way as the previous code but for some reason this is not setting the ProgressBar
to GONE
. Not sure what's wrong.
I've tried using clearAnimation
as suggested here Android, setVisbility to gone not working in RelativeLayout but still nothing.
spinner.clearAnimation();
spinner.setVisibility(View.GONE);
getActivity
instead ofviewInflated
– Concordia