I have a normal progressBar, but I need the progress to move from right to left instead of left to right.
I've tried using
android:layoutDirection="rtl"
and
android:layoutDirection="ltr"
even tried making a custom drawable for it too, made a progress.xml
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="-270"
android:toDegrees="270"
android:duration = "5000">
<shape
android:shape="ring"
android:innerRadiusRatio="3"
android:thicknessRatio="8"
android:useLevel="false">
<size
android:width="20dp"
android:height="20dp" />
<gradient
android:type="sweep"
android:useLevel="false"
android:startColor="#color/white"
android:endColor="#00ffffff"
android:angle="90"/>
</shape>
</rotate>
still not working
Please I need an idea of how to handle this.
Thank you in advance.
Try flipping your ProgressBar Simply by setting
android:scaleX="-1"
Try adding the following flag to your XML, I don't think you need a custom drawable. This should do the trick. What I mean is to add it your ProgressBar XML
android:rotation="180"
<ProgressBar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rotation="180"
/>
Related
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
I'm trying to do a circular progress bar run smoothly but I'm not having result. The progress bar should be update in function of a timer value.
Here is how I animate the progressbar,
int progress = (int)(this.mCurrentTimerValue/1000);
this.mProgressBarAnimation = ObjectAnimator.ofInt(this.mProgressBar,"progress",progress);
this.mProgressBarAnimation.setDuration(this.mCurrentTimerValue);
this.mProgressBarAnimation.setInterpolator( new LinearInterpolator());
where this.mCurrentTimerValue is the time in ml. For this example is 10000
And here is the result,
I want to show the progress smoothly but I can't. I tried with ObjectAnimator.ofFloat because the problem maybe is that I'm trying to progress in integer spaces but in that case animation doesn't work.
Here is how I customized the 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/progress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="#color/yellow"
android:endColor="#color/yellow"
android:startColor="#color/yellow"
android:type="sweep" />
</shape>
</rotate>
</item>
<item android:id="#android:id/secondaryProgress">
<rotate
android:fromDegrees="270"
android:toDegrees="270"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="25.0" >
<gradient
android:centerColor="#color/green"
android:endColor="#color/green"
android:startColor="#color/green"
android:type="sweep" />
</shape>
</rotate>
</item>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="false"
android:progress="100"
android:progressDrawable="#drawable/custom_progress_bar" />
I read these questions but didn't help me,
question 1
question 2
question 3
If somebody need a solution for this situation, this answer helped me but I admit I don't think is the best.
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"
I started porting my app into lollipop. I was able to theme the whole app to a particular color I like but I can't change the color of the ProgressDialog which is always green. Is there any way to do this?
You have to find the asset and change its color with photoshop, or create a new asset and use that as progress dialog.
The new asset can be created like :
<?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="0"
android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="8" android:useLevel="false">
<size android:width="76dip" android:height="76dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#447a29"
android:endColor="#447a29"
android:angle="0"
/>
</shape>
and call this progress.xml for example then use it like this :
<ProgressBar
android:id="#+id/ProgressBar01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background ="#xml/progress">
and you have only to change the start and end color to make it how you want it
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