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>
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 am new in Kotlin and trying to make a progress bar that is a HALF CIRCLE in my app and shows how much someone has spend so far.
There are many solutions for round ones and normal ones, but I can't find one for a half circle.
IN MY activity_main.xml FILE:
...
<ProgressBar
android:id="#+id/circularProgressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="250dp"
android:layout_height="250dp"
android:max="100"
android:progress="50"
android:layout_centerInParent="true"
android:progressDrawable="#drawable/circular"
android:secondaryProgress="100"/>
<TextView
android:id="#+id/tv"
android:layout_width="250dp"
android:layout_height="250dp"
android:gravity="center"
android:text="25$"
android:layout_centerInParent="true"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
AND IN MY circular.xml FILE:
...
<item android:id="#android:id/secondaryProgress">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<gradient
android:centerColor="#DADADA"
android:endColor="#999999"
android:startColor="#FFFFFF"
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="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<gradient
android:centerColor="#03A9F4"
android:endColor="#0063B1"
android:startColor="#68CCFF"
android:type="sweep" />
</shape>
</rotate>
</item>
WHAT I WANT is a horizontally cut circle as a progress bar.
I don't know if I am even on the right track and also I don't know how to set the degrees and things in the circular.xml file to get what I want, I tried but every time I changed something the output made no sense.
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.
this is my code from layout...
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rotate"
android:layout_centerInParent="true"
android:progressDrawable="#drawable/b"
android:visibility="gone" />
(b is a PNG)
android still showing default one
then tried this
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rotate"
android:layout_centerInParent="true"
android:progressDrawable="#drawable/rotate"
android:visibility="gone" />
as you can see I set progressDrawable to an drawable XML which I tried to copy from everywhere so I think the problem cant be there.
but anyway I will post it
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="7.0">
<gradient
android:centerColor="#007DD6"
android:endColor="#007DD6"
android:startColor="#007DD6"
android:angle="0"
android:type="sweep"
android:useLevel="false" />
</shape>
this is an extract from tutorials point
but android still showing the default one
also I made this but I have a suspicion that is a terrible mistake
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<bitmap android:src="#drawable/b"/>
</rotate>
but there is no way...
I am stuck no matter what I do Android still showing default one. anyone can help?
Use indeterminateDrawable , not progressDrawable.
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rotate"
android:layout_centerInParent="true"
android:indeterminateDrawable="#drawable/b"
android:visibility="gone" />
You cant use android:progressDrawable="some value" for animation.
1)Assign some id to rotate tag
2)write this in your activity.java file
Animation anim=AnimationUtils.loadAnimation(this,R.anim.id_of_your_rotate)
3)Retrieve the reference of ProgressBar
ProgressBar demo=new ProgressBar(this);
demo.setAnimation(anim);
I got a circular ProgressBar.
I want the circular not to rotate, but to fill in. Like say maxvalue is 100... let's say setprogress(10) then 10 % of the progress bar is colored... and so on
how can this be done? How can I handle it? it keeps rotating over and over....
progress_bar.xml
<ProgressBar
android:id="#+id/progress"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="20dp"
android:indeterminate="false"
android:indeterminateDrawable="#drawable/progress_bar"
android:max="100" />
progress_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%">
<shape android:shape="ring" android:innerRadiusRatio="4"
android:thicknessRatio="48" android:useLevel="false">
<size android:width="18dip" android:height="18dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#52c1b1" android:centerColor="#52c1b1"
android:endColor="#ffffff" android:centerY="0.50" />
</shape>
</animated-rotate>
There is not direct way to achieve what you want. The only way, AFAIK, is to have a custom ProgressBar and override onDraw. Through the canvas you get as parameter you can draw an arc, for instance representing the percentage of your progress.