Felipe Caldas
Felipe Caldas

Reputation: 2503

ProgressBar not showing in some devices

I have the following layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.pontai"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.markupartist.android.widget.ActionBar
        android:id="@+id/actionbar"
        style="@style/ActionBar"
        android:layout_marginBottom="3dip"
        app:textStyleActionBar="@style/TextViewStyleHeader"
        app:title="@string/app_name" />

    <com.fb.design.SegmentedButton
        android:id="@+id/main_action_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:btnText1="@string/sb_friends"
        app:btnText2="@string/sb_search"
        app:btnText3="@string/sb_summary"
        app:gradientColorOffEnd="@color/segmented_button_off_end"
        app:gradientColorOffStart="@color/segmented_button_off_start"
        app:gradientColorOnEnd="@color/segmented_button_on_end"
        app:gradientColorOnStart="@color/segmented_button_on_start"
        app:gradientColorSelectedEnd="@color/segmented_button_selected_end"
        app:gradientColorSelectedStart="@color/segmented_button_selected_start"
        app:whichButtonIsSelected="0" />

    <View
        android:layout_width="wrap_content"
        android:layout_height="2dp"
        android:layout_marginBottom="3dip"
        android:background="@drawable/gradient_line" >
    </View>

    <LinearLayout
        android:id="@+id/linearLayout7"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/buttonAddFriends"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_input_add"
                android:clickable="true"
                android:height="40dp"
                android:width="40dp" />

            <EditText
                android:id="@+id/search_box"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="@string/type_here_to_filter"
                android:inputType="text"
                android:maxLines="1"
                android:padding="10dp" >
            </EditText>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/loadingPanel"
            style="@style/GenericProgressBackground"
            android:layout_height="match_parent" >

            <ProgressBar style="@style/GenericProgressIndicator" />
        </LinearLayout>

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

        <TextView
            android:id="@id/android:empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="5dp"
            android:text="@string/empty_results" />
    </LinearLayout>
</LinearLayout>

My Activity has a AsyncTask that upon completion does the following:

((LinearLayout)findViewById(R.id.loadingPanel)).setVisibility(View.GONE);

So, basically I have a LinearLayout holding my ProgressBar and, when I have the data I need, I set the visibility to GONE for this linearlayout.

This is working find on my Galaxy Nexus, but it's not working on my API 8 Emulator and also in the Galaxy S2, using a custom ROM.

Has anyone ever seen this?

My worst case scenario will be removing this linearlayout with a progress bar from the XML and add a ProgressDialog in the code.

Regards, Felipe

UPDATE

This is how I defined the styles.xml

 <style name="GenericProgressBackground" parent="android:Theme">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:background">#77ffffff</item>
        <item name="android:gravity">center</item>
    </style>

    <style name="GenericProgressIndicator" parent="@android:style/Widget.ProgressBar.Large">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:indeterminate">true</item>
    </style>

UPDATE2 I fixed the issue

 <ProgressBar
                android:id="@+id/progressBar1"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

I added the style coming from the android attributes and that alone worked... I have no idea why it didnt work with the style I created... it's weird.

Thanks for the help! :)

Upvotes: 6

Views: 8778

Answers (6)

Satheesh
Satheesh

Reputation: 11276

I had a weird issue on an HTC U11 where our battery saver was automatically turned on, I turned it off but still, the spinner was not showing up.

Then I turned off developer settings totally, relaunched the app and then the Spinner start showing up, hope it helps someone.

Upvotes: 0

Amitoj Singh
Amitoj Singh

Reputation: 59

My solution to this was switching to Linear layout from Relative Layout. Worked Quite Well. Code below hope it helps

activity_main.xml:

 <LinearLayout
        android:id="@+id/leniar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="@color/colorPrimary"
        android:baselineAligned="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:weightSum="3">


        <ProgressBar
            android:id="@+id/progressBarlite"
            style="@style/Widget.AppCompat.ProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"


            android:gravity="center"
            android:theme="@style/ProgressBarlit" />

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipeContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:layout_marginTop="0dp"
            android:layout_marginBottom="-1dp"
            android:background="@color/colorPrimaryDark"
            android:visibility="visible">

            <WebView
                android:id="@+id/webview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true">

            </WebView>
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>

Yes I have a WebView and SwipeRefreshLayot Too But i Guess you can just copy this code and delete those segments. and if wondering how i make the progress bar show in the center of the screen:

MainActivity.java:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

                    setTheme(R.style.AppTheme);
                    setContentView(R.layout.activity_main);


     this.progressBar = findViewById(R.id.progressBarlite);
     mySwipeRefreshLayout = 
       (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);
     this.webview = findViewById(R.id.webview);


WebViewClientImpl webViewClient = new WebViewClientImpl(this);
                webview.setWebViewClient(webViewClient);


                webview.setVisibility(View.GONE);
                mySwipeRefreshLayout.setVisibility(View.GONE);


 public class WebViewClientImpl extends WebViewClient {

            private Activity activity = null;


            public WebViewClientImpl(Activity activity) {
                this.activity = activity;

            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView View, String url) {

//here i set the domains the webview can browse
                if (url.contains("ur domain"))
                    return false;
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                activity.startActivity(intent);

                return true;


            }

//here i show the progress bar
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                mySwipeRefreshLayout.setVisibility(View.GONE);
                progressBar.setVisibility(View.VISIBLE);
                webview.setVisibility(View.GONE);

            }

//here i hide the progress bar
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);

                progressBar.setVisibility(View.GONE);
                webview.setVisibility(View.VISIBLE);
                mySwipeRefreshLayout.setVisibility(View.VISIBLE);

                if (mySwipeRefreshLayout.isRefreshing()) {
                    mySwipeRefreshLayout.setRefreshing(false);
                }

            }

//here i hide the progress bar and also load a locally saved error messege
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String url) {
                view.loadUrl("file:///android_asset/error.html");
                progressBar.setVisibility(View.GONE);
                mySwipeRefreshLayout.setVisibility(View.VISIBLE);
                webview.setVisibility(View.VISIBLE);

                if (mySwipeRefreshLayout.isRefreshing()) {
                    mySwipeRefreshLayout.setRefreshing(false);
                }

            }

            public class MediaWebView extends WebView {

                public MediaWebView(Context context) {
                    super(context);
                }

                public MediaWebView(Context context, AttributeSet attrs) {
                    super(context, attrs);
                }

                public MediaWebView(Context context, AttributeSet attrs, int defStyleAttr) {
                    super(context, attrs, defStyleAttr);
                }

                @Override
                protected void onWindowVisibilityChanged(int visibility) {
                    if (visibility != View.GONE) super.onWindowVisibilityChanged(View.VISIBLE);
                }

            }

        }
}

For this to work it's really important that you call out the gravity to be "center" for both the progress bar and the linear layout containing it

<LinearLayout
        android:gravity="center"/>


        <ProgressBar
            android:gravity="center"/>
</LinearLayout>

here is my styles.xml:

<resources>
 <style name="ProgressBarlit" parent="Theme.AppCompat">
        <item name="colorAccent">@color/progressback</item>
        <item name="android:minWidth">32dp</item>
        <item name="android:maxWidth">50dp</item>
    </style>
    <style name="ProgressBardrk" parent="Theme.AppCompat">
        <item name="colorAccent">@color/colorAccentDarkprgress</item>
        <item name="android:minWidth">32dp</item>
        <item name="android:maxWidth">50dp</item>
        <item name="android:minHeight">32dp</item>
        <item name="android:maxHeight">100dp</item>
    </style>


</resources>

Hope It Helps and i know it answers more than just this question but you will find your answer in here

Upvotes: 0

Stoycho Andreev
Stoycho Andreev

Reputation: 6283

On some devices the progress bar could not appear because in Settings -> Developer Options -> Transition Animation Scale is OFF.

Switching this setting to ON (usually x 1) will make the progress bar to appear again.

I guess there is a proper explanation about that, but I do not have complete answer why animations off make the progress bar to not work.

Upvotes: 6

Cristan
Cristan

Reputation: 14135

This can happen on some devices when animations are turned off. Turn your animations on again and you should be fine.

Upvotes: 2

Merve Gencer
Merve Gencer

Reputation: 87

I had the same problem. I wanted to add a progress bar on my splash screen in xml layout file, I was able to see the progress bar showing on Eclipse preview of the screens, but when I run the code, it was invisible and it made me crazy for a couple of hours. Finally I solved the issue by adding the progress bar in a FrameLayout, with the splash background image drawing in a different RelativeLayout which is a lower layer child of the FrameLayout. My background image was a 9patch image, so maybe it was overwriting my progressbar on runtime. But here is my solution:

<FrameLayout 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"
    android:layout_gravity="center" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/splash" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_marginTop="150dp"
        android:visibility="visible" />

</FrameLayout>

Hope it helps!

Upvotes: 1

Alexandre B.
Alexandre B.

Reputation: 495

What is the result of using

<ProgressBar
        style="@android:style/Widget.DeviceDefault.ProgressBar.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

Upvotes: 4

Related Questions