Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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! :)

like image 808
Felipe Caldas Avatar asked Apr 27 '12 14:04

Felipe Caldas


4 Answers

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.

like image 161
Stoycho Andreev Avatar answered Nov 03 '22 18:11

Stoycho Andreev


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" />
like image 20
Alexandre B. Avatar answered Nov 03 '22 19:11

Alexandre B.


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

like image 2
Cristan Avatar answered Nov 03 '22 19:11

Cristan


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!

like image 1
Merve Gencer Avatar answered Nov 03 '22 19:11

Merve Gencer