Progressbar indeterminate drawable vs progressDrawable - android

I need to create spinner circulate progressbar that circulate starting from bottom (progress go from 0 to max) to top and when reaches to top starting to minimized(progress max to 0) and then stating again from bottom.
Here is my prgressbar
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="70dp"
android:layout_height="70dp"
android:id="#+id/progressBar2"
android:indeterminateDrawable="#drawable/progressbar_circle"
android:progressTintMode="src_atop"
android:layout_centerInParent="true"
android:indeterminateDuration="500"
android:layout_marginTop="189dp"
android:indeterminateOnly="true"
/>
Here is the drawable progressbar_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="90"
android:toDegrees="270">
<shape android:shape="ring"
android:thicknessRatio="13" android:useLevel="false">
<size android:width="76dip" android:height="76dip" />
<gradient android:type="sweep" android:useLevel="false"
android:centerColor="#000cbdfb"
android:endColor="#f168c1"
android:angle="0"
/>
</shape>
</rotate>
When in my progressbar I give drawable as indeterminateDrawable. It's only circulate from bottom to top and begin from bottom immediately(I can't reach to effect when in top it starts to minimized).

change your rotate drawable parameters like this
android:fromDegrees="90"
android:toDegrees="450"

Related

How to recreate the progress bar rotation?

How can I recreate the rotation of a ProgressBar of type progressBarStyleLarge?
I have this layout:
<androidx.core.widget.ContentLoadingProgressBar
android:id="#+id/loadingIndicator"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:indeterminateDrawable="#drawable/loadingindicator"
style="?android:attr/progressBarStyleLarge" />
Drawable loadingindicator:
<?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:duration="0"
android:toDegrees="360" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="40"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:startColor="#ff00ff"
android:centerColor="#ff00ff"
android:endColor="#ffffff"
android:centerY="0.50"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
But this causes a smooth constant rotation instead of the - I believe - 2 parallel rotations that are displayed with the default style.
Specifically I want to recreate the animation of the Indeterminate circular progress indicator, as shown here:
https://material.io/components/progress-indicators/#circular-progress-indicators
XY question disclosure:
I need this because I want to customize the stroke thickness and outer margin of the ProgressBar.
You could use CircularProgressDrawable in code like:
val drawable = CircularProgressDrawable(context).apply {
strokeWidth = // desired width in pixels
}
progressBar.indeterminateDrawable = drawable
Documentation:
https://developer.android.com/reference/android/support/v4/widget/CircularProgressDrawable

Change custom progress bar color on every rotation

I am using a custom progress bar which works fine.
I used start, center, end color in code.
But need to change color of progress bar on every rotation. (Every time when progress bar reaches 360 degree rotation, the color has to be changed.)
Please find the code below with single color rotation.
progressdialog.xml
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1"
android:toDegrees="1080" >
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="20"
android:useLevel="false" >
<size
android:height="48dip"
android:width="48dip" />
<gradient
android:centerColor="#color/translucent_red"
android:centerY="0.50"
android:endColor="#color/translucent_red"
android:startColor="#4fff"
android:type="sweep"
android:useLevel="false" />
</shape>
main_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/progressdialog" >
</ProgressBar>
Any help would be really thankful.

Creating a bent line like an arc in Android using xml in drawable

What I did..
<item>
<rotate
android:fromDegrees="40"
android:toDegrees="20"
android:pivotX="25%"
android:pivotY="50%" >
<shape
android:shape="line"
android:top="1dip" >
<stroke
android:width="1dip"
android:color="#FF0000" />
</shape>
</rotate>
</item>
It rotates but doesn't bend. It needs to be bent to form an arc like shape
Any Idea?
You can draw a ring shape, rotate it based on your preference and use it with ProgressBar as progressDrawable with a set progress.
drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="150"
android:toDegrees="150">
<shape
android:shape="ring"
android:thickness="10dp"
android:innerRadius="20dp"
android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->
<solid android:color="#color/colorPrimary"/>
</shape>
</rotate>
layout.xml
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="120dp"
android:layout_height="120dp"
android:progressDrawable="#drawable/widget_arc"
android:indeterminate="false"
android:max="100"
android:progress="67"
/>
You can set the progress dinamically and also easy to animate it
*Use dimen res values

Circular progress bar left right edge gets cut

I have created circular progress bar and its working fine but the problem is that the left and right edge gets cut.
i cant figure out why is it happening or how to fix it.
Its in a relative layout
Relativelayout containing progressbar
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/Button_searchdriver_Cancel"
android:layout_below="#id/searchDriver_center"
android:padding="3dp"
>
<ProgressBar
android:id="#+id/Progressbar_searchdriver_timer"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="#drawable/progressbackground"
android:indeterminate="false"
android:max="60"
android:progressDrawable="#drawable/circularprogress" />
</RelativeLayout>
For background and progress i have the following code -
Progress drawable
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="7.0">
<gradient
android:centerColor="#ffffff"
android:endColor="#ffffff"
android:startColor="#ffffff"
android:angle="0"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
progressbar background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.5"
android:shape="ring"
android:useLevel="false"
android:thicknessRatio="7.0">
<gradient
android:centerColor="#000000"
android:endColor="#000000"
android:startColor="#000000"
android:angle="0"
android:type="sweep"
android:useLevel="false" />
</shape>
Can any one tell me what am i doing wrong..??
set
android:innerRadiusRatio="3.0"
According to the docs
innerRadiusRatio is the radius for the inner part of the ring, expressed as a ratio of the
ring's width. For instance, if android:innerRadiusRatio="5", then the
inner radius equals the ring's width divided by 5. This value is
overridden by android:innerRadius. Default value is 9.

How to make ProgressBar stop spinning?

When I add horizontal ProgressBar it behaves as expected -- I set the progress value and it shows it.
However when I add ProgressBar (circular) it spins. And that's it. In such form it is more "please wait" indicator, that any progress bar, because progress value is not shown.
So my question is (assuming Progress in name means progress) -- how to stop spinning and shows progress value? For example if I set max to 100, and value to 50 I would expect to see half-circle arc.
In other words how to make circular ProgressBar to behave like horizontal ProgressBar, with only exception of the shape?
I know that this is an old post but I ran into the same issue and I make it work.
It is actually easier than you think, you have to set a custom progress in an xml file inside your drawable folder and handle the attributes "fromDegrees" and "toDegrees" from the < rotate > tag:
This is the code for custom_progress.xml (you can customize yours as you like but you must not modify "fromDegrees" and "toDegrees")
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#0099ff"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="-90"
android:toDegrees="-90">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#e0e0e0"/>
</shape>
</rotate>
</item>
</layer-list>
And for your progress bar you have to set this attributes:
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="100dp"
android:layout_height="100dp"
android:indeterminate="false"
android:max="100"
android:progress="20"
android:progressDrawable="#drawable/custom_progress" />
What is happening here is that the progress will start in degree -90 which for me is the top side of the progress bar view and towards the right and it will continue towards the same degree, this will make the view progress to start and end in the same degree.
NOTE:
If you set 0 for both "fromDegrees" and "toDegrees" the progress will start from the right side of the circle.
Hope it helps people with the same requirement.
Since Api 21 you can do something like that: Assuming that your ProgressBar defind this way:
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/progressBarStyleLarge"
android:id="#+id/progress_bar"
android:layout_width="#dimen/item_width"
android:layout_height="#dimen/item_height"
android:clickable="false"
android:indeterminate="true"
android:indeterminateDrawable="#drawable/progress"/>
and this is progress.xml:
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="8"
android:useLevel="false" >
<size
android:height="76dip"
android:width="76dip" />
<gradient
android:angle="0"
android:endColor="#color/colorGrayText"
android:startColor="#android:color/transparent"
android:type="sweep"
android:useLevel="false" />
</shape>
Now you can do this on your ProgressBar:
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
if (progressBar != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
RotateDrawable rotateDrawable = (RotateDrawable) progressBar.getIndeterminateDrawable();
rotateDrawable.setToDegrees(0);
}
}
Like toadzky commented, there's no baked-in method. You might try this ProgressWheel. If nothing else, it should give you idea of how to implement it.
For determinate progress bar means the progress bar which doesn't keep on rotating and user can set a fixed percentage over that.
<ProgressBar
android:id="#+id/pb_sharpness"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="#dimen/dp_50"
android:layout_height="#dimen/dp_50"
android:layout_marginTop="#dimen/dp_16"
android:indeterminate="false"
android:max="100"
android:progressDrawable="#drawable/custom_progress_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
For adding drawable to above progress bar
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="15.0">
<solid android:color="#color/white_color"/>
</shape>
</item>
<item android:id="#android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="180"
android:toDegrees="0"
>
<shape
android:innerRadiusRatio="2.3"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="15.0">
<gradient
android:startColor="#color/color_5646F3"
android:endColor="#color/color_ED88FE" />
</shape>
</rotate>
</item>
You can access the visibility property of the progress bar and set it to invisible when you need it to be invisible like this
ProgressBar progressBar = view.findViewById<ProgressBar>(R.id.progressbar)
progressBar.visibility = ProgressBar.INVISIBLE

Categories

Resources