Smoother and faster rotation on ProgressDialog - android

I have a custom animation to my ProgressDialog which is set this way:
pd.setIndeterminateDrawable(c.getResources().getDrawable(R.anim.progress_animation));
The progress_animation is like this:
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="358" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:centerColor="#4c737373"
android:centerY="0.50"
android:endColor="#E66A0F"
android:startColor="#4c737373"
android:type="sweep"
android:useLevel="false" />
</shape>
</animated-rotate>
This will give me an orange spinning wheel, but this seems to be "slower" or more laggy than the default spinning wheel in the ProgressDialog. I've tried setting the android:toDegrees from 360 to 358, but with no luck. I have also enabled hardware acceleration. Is there anyway I can make this animation smoother, or faster?
Thanks!

Use "rotate" instead of "animated-rotate" and change android:toDegrees should make it go faster.
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="2160" />

This works for me:
Create my_progress_indeterminate.xml at drawable(created).
The load_spool.png is the Image to rotate.
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/load_spool"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="2160">
</rotate>
The Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="#drawable/my_progress_indeterminate" />
</LinearLayout>

try android:toDegrees="1080" i my case it works .... just try this

Related

Android: how to animate a circular ProgressBar with a mask?

I want to create a circular ProgressBar animating within a custom shape, like this:
I already know how to create a basic circular ProgressBar:
<ProgressBar style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="80dp"
android:layout_height="80dp"
android:indeterminate="false"
android:max="6000"
android:progress="0"
android:progressDrawable="#drawable/shape_ring_blue_progress" />
shape_ring_blue_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:shape="ring"
android:innerRadiusRatio="2.17391304"
android:thicknessRatio="25.0"
android:useLevel="true">
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
<solid
android:color="#color/style_color_blue" />
</shape>
</rotate>
</item>
</layer-list>
But I have no clue of how to use a more complex shape and a mask like I want to.
Thanks for your help!

Android custom circular ProgressBar direction

I have a custom Circular Progressbar. This is the drawable I have for it to be determinate:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/secondaryProgress">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<gradient
android:centerColor="#999999"
android:endColor="#999999"
android:startColor="#999999"
android:type="sweep" />
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<rotate
android:fromDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
<gradient
android:centerColor="?attr/colorAccent"
android:endColor="?attr/colorAccent"
android:startColor="?attr/colorAccent"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
I want it to show the progress in a clockwise direction, but now it's showing counterclockwise.
How do I change it?
I guess you're using an rtl language? You can force the progress bar to an ltr or clockwise direction by setting the layoutDirection property on your ProgressBar.
<ProgressBar
...
android:layoutDirection="ltr" />
By using latest versions of material design library, you can achieve this:
in the layout with this attribute
app:indicatorDirectionCircular
or programmatically with this method
setIndicatorDirection()
Refer here for more info.
Change this
<rotate
android:fromDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
to
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
I'm not sure if it will work, but just try to set android:toDegrees="-360" like this :
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-360" />
you can change rotation on Y axis by 180 degrees
android:rotationY="180"

How to customozation loading ui android?

this is the normal loading "image" is shown in android
I want to customization for example change it to ..
or
how do we replace the first loading for them? do we need pics? or some xml file?
res/layout.xml
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"
android:indeterminateDrawable="#drawable/progress" >
</ProgressBar>
drawable/progress.xml This is a custom ProgressBar that i use to change the default colors.
<?xml version="1.0" encoding="utf-8"?>
<!--
Duration = 1 means that one rotation will be done in 1 second. leave it.
If you want to speed up the rotation, increase duration value.
in example 1080 shows three times faster revolution.
make the value multiply of 360, or the ring animates clunky
-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1"
android:toDegrees="360" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:centerColor="#color/color_preloader_center"
android:centerY="0.50"
android:endColor="#color/color_preloader_end"
android:startColor="#color/color_preloader_start"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>

How to decrease the speed of custom ProgressBar

I have implemented a custom progress bar and I am displaying it while getting data from an URL, it is working fine as progress bar is spinning, but my problem is that I am not able to find a proper way to decrease its revolving speed, currently it is spinning very fast.
please help me with your suggestions and reply.
xml layout for progress bar:-
<ProgressBar
android:id="#+id/showProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminateDrawable="#drawable/my_progress_indeterminate" />
Also here's "my_progress_indeterminate" which is used to rotate my custom progressbar :-
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/image_loading"
android:pivotX="50%"
android:pivotY="50%" />
please share some example if possible to decrease the speed of rotation.
Any suggestions will be appreciated.
add in code to progress.xml
android:fromDegrees="0"
android:toDegrees="1080" <!-- Add in code to progress custumize xml to speed up -->
Try this. It will help you.
Create progressbar_custom.xml
/res/drawable/progressbar_custom.xml:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >
<shape
android:innerRadius="18dp"
android:shape="ring"
android:thickness="5dp"
android:useLevel="false" >
<size
android:height="48dp"
android:width="48dp" />
<gradient
android:centerColor="#802A67AD"
android:centerY="0.5"
android:endColor="#ff2A67AD"
android:startColor="#002A67AD"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
Add Progressbar in XML files
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="#drawable/progressbar_custom" />
Use "rotate" instead of "animated-rotate" and changing android:toDegrees or android:toDegress should make it go slower.
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/image_loading"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />

Android Custom ProgressBar not Rotating

I want to change the default animation of a ProgressBar, so I added a custom style in my theme:
styles.xml
<style name="ProgressTheme" parent="#android:style/Widget.ProgressBar.Large">
<item name="android:indeterminateDrawable">#drawable/spinner_holo_light</item>
</style>
I am calling this style inside my ProgressBar with the following:
ProgressBar.xml
<ProgressBar
android:id="#+id/loadingProgressBar"
style="#style/ProgressTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
The problem lies inside the spinner_holo_light.xml:
If I use the following, everything works fine on devices with os 3.0+, but the progress does not rotate on older os versions:
spinner_holo_light.xml
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/spinner_76_inner_holo"
android:fromDegrees="720"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
But if I use animate-rotate instead, the animation works on every os version, but the result is a very laggy animation.
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/spinner_76_inner_holo"
android:fromDegrees="720"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
What do you think about it? Am I doing something wrong here?
On older devices it is a problem when android:fromDegrees is bigger than android:toDegress in <rotate>. Try swapping the values:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/spinner_76_inner_holo"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="720" />
Alternatively, you can try setting it as infinite:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/spinner_76_inner_holo"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite" />
The animation might be laggy on older devices. To fix this add android:animationResolution to the style:
<style name="ProgressTheme" parent="#android:style/Widget.ProgressBar.Large">
<item name="android:indeterminateDrawable">#drawable/spinner_holo_light</item>
<item name="android:animationResolution">33</item>
</style>
Make transparent background of progress dialog.
Make border less progress dialog.
And customization of color of spinner of circular progress dialog.
http://pankajchunchun.wordpress.com/2011/09/10/customization-of-spinner-progress/
I couldn't get it work on Samsung Galaxy S Plus even adding
<item name="android:animationResolution">33</item>
I was asking something similar to your response #Tomik
Android Progress Bar slow rotation on pre HoneyComb devices
Is it smoothly on all the pre honeycomb devices for sure?
I Solved this Problem by Changing BackGround xml Custom format to indeterminateDrawable
Use android:indeterminateDrawable except android:BackGround
<ProgressBar
android:layout_centerHorizontal = "true"
android:layout_centerVertical = "true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable = "#drawable/progressbar"
android:id="#+id/progressBar"
android:indeterminate = "true"/>
And Custom Progressbar XML Code
<?xml version="1.0" encoding="utf-8" ?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="7" android:useLevel="false">
<size android:width="76dip" android:height="76dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#android:color/transparent"
android:endColor="#00FF00"
android:angle="0" />
</shape>
</rotate>

Categories

Resources