I want to creat a circular ProgressBar with rounded edge. I have tried CircleProgress library hosted here
https://github.com/lzyzsd/CircleProgress
But the DonutProgress don't have rounded edge which I want. But with my custom progreesDrawable also I am not able to achieve it.
I want to design progress bar as shown below
One corner Rounded as marked in picture.
My custom_progress_bar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="90"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="15.0" >
<corners
android:radius="5dp"
android:topRightRadius="5dp"
android:topLeftRadius="5dp"
/>
<gradient
android:centerColor="#8AFF00"
android:endColor="#006554"
android:startColor="#006554"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>
My layout file
<RootLayout...>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="152dp"
android:layout_height="152dp"
android:layout_centerInParent="true"
android:progress="100"
android:indeterminate="false"
android:progressDrawable="#drawable/back_progress" />
<ProgressBar
android:id="#+id/progressWheel"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="152dp"
android:layout_height="152dp"
android:layout_centerInParent="true"
android:progress="90"
android:indeterminate="false"
android:progressDrawable="#drawable/circular_progress_bar" />
</RootLayout...>
Also I had to use two ProgressBar overlapping each other just to achieve the background thing(grey). I tried defining the background shape too inside my custom_progress_bar.xml but it was not working, so I had to do this. I know its not the solution but I was not able to make it happen by other way.
Can anybody help me to design this progress bar in better way with rounded edge too.
I'm a little late to the party, but the code I added in my fork of castorflex's smoothProgressBar can create the progress bar you are describing! the library already had rounded edge progress bar and a friend and I (shout out to Ryan) were able to get the gradient working with it nicely. https://github.com/alex-sanchez-sd/SmoothProgressBar
Related
I am new to Android. I am having problem in setting up the custom shape of SliderLayout. I am using Daimajia Library for this. Can anyone please help.
I am posting the xml below (Shape I required)
<!-- Colored rectangle-->
<item android:top="0dp"
android:bottom="-10dp">
<shape android:shape="rectangle">
<size
android:width="335dp"
android:height="#dimen/dp300" />
<solid android:color="#FF0000" />
</shape>
</item>
<item
android:top="265dp"
android:bottom="-50dp"
android:right="-10dp"
android:left="-10dp">
<rotate
android:fromDegrees="-8">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
Daimajia SliderLayout is a custom 3rd party library Slider layout.. and as at now it doesn't even show the "Android:background" attribute in it for you to be able make a custom shape and set that custom shape as its background shape...
So honestly, it will remain as a Rectangle for now and cant be curved and changed to a different shape....
Maybe unless you research and use a totally different slider layout library where you can change its shape
finally after 2 hours dealing with this problem i found the answear.
first you need to add [ implementation 'com.jcminarro:RoundKornerLayouts:0.4.0'
] library which help you curve any layer u want : this is an example :
<com.jcminarro.roundkornerlayout.RoundKornerRelativeLayout
android:id="#+id/rtl_slider_advertisment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="16dp"
app:corner_radius="5dp">
<com.daimajia.slider.library.SliderLayout
android:id="#+id/slider_advertisment"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
<com.jcminarro.roundkornerlayout.RoundKornerRelativeLayout
android:background="#drawable/gold_line"
android:layout_width="match_parent"
android:layout_height="200dp"></com.jcminarro.roundkornerlayout.RoundKornerRelativeLayout>
</com.jcminarro.roundkornerlayout.RoundKornerRelativeLayout>
I want add background drawable to the progress bar. So, i use android:background for background and android:progressDrawable for the progress drawable and when I add those resources, it looks wierd because progress drawable looks smaller than the background and I want it to be "fitted" with background - the same size as the background. I use classic HDPI, XHDPI, etc. icons for background. I just want that progress view and background have the same size. Has anyone else tried to add background to a progress view?
This is the ProgressBar
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="false"
android:indeterminateOnly="false"
android:background="#drawable/ic_message_cancel"
android:max="100"
android:progress="50"
android:progressDrawable="#drawable/circular_progress_bar" />
and circular_progress_bar:
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270" >
<shape
android:shape="ring"
android:useLevel="true" >
<gradient
android:angle="0"
android:endColor="#color/gray"
android:startColor="#color/gray"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
So I'm trying to create a custom SeekBar. Before I thought what I wanted would be accomplishable with a ProgressBar so when I had it as a progress bar it worked fine, I was able to change the colors as I needed using custom drawables. The problem arose when I needed to incorporate a "thumb".
Immediately after I changed the ProgressBar to a SeekBar the seekbar "shrinks" and no longer fits the outline. The first images show the seekbar not fitting the dimensions...
This image is an example of what I'm trying to accomplish...
You may also notice that the white "gap/thumb" that I have there is not lined up with the correct place (where the colored drawable ends)
I suspect this is related to the unexplained shrinking that is happening?
Note: When I set the padding of the SeekBar to 0 the view snaps back to the correct dimensions but the "thumb" is still offset and I think this is related to the spacing...
Here is the XML for the SeekBar
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imageView1"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingRight="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<SeekBar
android:id="#+id/call_status_progress"
android:layout_width="match_parent"
android:layout_height="7dp"
android:focusable="false"
android:layout_marginTop="3dp"
android:progressDrawable="#drawable/status_waiting_drawable"
android:thumb="#drawable/seeker"
android:progress="1"
android:max="6"
android:indeterminate="false" />
</LinearLayout>
...
</LinearLayout>
And here is the XML for the background drawable
<?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>
<corners android:radius="2px" />
<gradient
android:startColor="#D8D8D8"
android:centerColor="#D8D8D8"
android:centerY="0.75"
android:endColor="#D8D8D8"
android:angle="270"
/>
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="2px" />
<gradient
android:startColor="#color/status_waiting"
android:centerColor="#color/status_waiting"
android:centerY="0.75"
android:endColor="#color/status_waiting"
android:angle="270"
/>
</shape>
</clip>
</item>
I found the answer after searching for a long time, as normal these obscure errors usually prove to be simple mistakes or overlooked attributes.
For me my solution was setting the attribute
android:thumbOffset
android:thumbOffset="0dp"
I hope this solution will help others in the future.
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.
i am trying to change the color of horizontal progress bar but it is not changing. i did some googling and gone through some example given in ur site. But i am not getting success to change the color accurately.
i used progressBar.setProgressDrawable(Drawable d) but it sets the background color of the whole progress bar view instead of setting the background color of only the bar itself.
Please, any body help me.
thanks
Hi I am using this code in my project. I hope it works for you.
// Create ProgressBar in your layout file.
<ProgressBar
android:id="#+id/yourid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progressDrawable="#drawable/slider"
/>
// Create .xml file in your drawable folder with name slider.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#android:id/background"
android:drawable="#drawable/grey_bar_music"/>
<item android:id="#android:id/progress">
<clip android:drawable="#drawable/blue_bar_music" />
</item>
</layer-list>
//grey_bar_music ->Background image name for your progressbar.
//blue_bar_music->Progress bar change color using this image when it start from 0.
You Can create custom_progress.xml file in drawable folder -
<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="2"
android:thicknessRatio="6" android:useLevel="false">
<size android:width="76dip" android:height="76dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="#c76a37"
android:endColor="#A4B4B9"
/>
</shape>
</rotate>
//And add below code to your layout file to create progress bar
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="68dp"
android:progressDrawable="#drawable/custom_progress"
/>
Hope this will help you.