Custom Vertical Progress Bar - android

I've made a custom vertical progress bar and I want to show labels along side it.
<?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>
<solid android:color="#777" />
</shape>
</item>
<item android:id="#android:id/progress">
<layer-list>
<item>
<clip
android:clipOrientation="vertical"
android:gravity="bottom">
<shape>
<gradient
android:angle="90"
android:centerColor="#FFFF00"
android:endColor="#FF0000"
android:startColor="#00FF00" />
</shape>
</clip>
</item>
<item>
<clip
android:clipOrientation="vertical"
android:gravity="fill">
<layer-list>
<item android:top="75dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#333" />
</shape>
</item>
<item android:top="25dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#333" />
</shape>
</item>
<item android:bottom="25dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#333" />
</shape>
</item>
<item android:bottom="75dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#333" />
</shape>
</item>
</layer-list>
</clip>
</item>
</layer-list>
</item>
</layer-list>
Usage:
<ProgressBar
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="10dp"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/form_items_margin"
android:layout_gravity="center"
android:max="100"
android:progress="90"
android:progressDrawable="#drawable/progress_drawable_vertical" />
This is what mine looks like
This is What I wanted
Of course I couldn't achieve exactly like this But I only want to show labels alongside this now. I know I can make another vertical layout and show textview labels but that would be too messy. Is there any way I could adjust it in layer-list layout.

Related

How to make oval shape of progress in horizontal progress-bar in android

This background drawable.xml
<?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="12dp" />
<solid android:color="#cccccc" />
</shape>
</item>
<item android:id="#android:id/progress"
>
<clip>
<shape>
<corners android:radius="12dp" />
<solid android:color="#color/colorPrimaryDark" />
</shape>
</clip>
</item>
</layer-list>
Below is my progress-bar
<ProgressBar
android:id="#+id/pb"
style="#android:style/Widget.Holo.Light.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv"
android:hapticFeedbackEnabled="true"
android:progressDrawable="#drawable/point_default_progess"
android:progress="2"
android:scaleY="0.80" />
I want to set progress shape inside progress-bar with oval shape but i am unable to set oval shape. please suggest me how to fix this issue below is my screen .
I want to make progress view in oval shape please help me in this issue.
Expected image is below
i want to set oval shape below 3 progress value .
background_drawable.xml
<?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>
<solid android:color="#777" />
<size
android:width="15dp"
android:height="15dp" />
<corners android:radius="10dp" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<layer-list>
<item>
<color android:color="#00000000" />
</item>
<item
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp">
<shape>
<solid android:color="#068310" />
<size
android:width="15dp"
android:height="15dp" />
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
</clip>
</item>
</layer-list>
progress-bar.xml
<ProgressBar
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:progressDrawable="#drawable/background_drawable" />
hope it helps.
just replace <clip> with <scale>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="12dp" />
<solid android:color="#cccccc" />
</shape>
</item>
<item android:id="#android:id/progress">
<scale android:scaleWidth="100%">
<shape>
<corners android:radius="12dp" />
<solid android:color="#color/colorPrimaryDark" />
</shape>
</scale>
</item>

how to set image in proper position in layers in layer-list?

I am trying to set image in center of circle like this
(trying it on android 4.1.2)
but when I run the app it shows image like this
but when i am writing code in xml it shows right image like
Here is the xml code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="-1dp"
android:left="-1dp"
android:bottom="-1dp">
<shape>
<solid android:color="#50000000" />
<corners android:radius="50dp" />
</shape>
</item>
<item android:height="20dp" android:width="20dp">
<shape>
<corners android:radius="50dp" />
<stroke android:color="#color/white"
android:width="1dp"/>
<solid android:color="#50000000"/>
</shape>
</item>
<item android:width="8dp"
android:height="8dp"
android:gravity="center"
android:drawable="#drawable/news">
</item>
</layer-list>
You can try this,
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#50000000"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke
android:width="1dp"
android:color="#color/colorAccent"/>
<solid android:color="#50000000"/>
</shape>
</item>
<item
android:bottom="5dp"
android:drawable="#drawable/news"
android:gravity="center"
android:left="5dp"
android:right="5dp"
android:top="5dp">
</item>
</layer-list>

Android - How to put round corner on the running progress in a progress bar using custom xml drawable as background

I'm using a custom drawable for my progress bar:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="15dp" />
<solid android:color="#color/light_grey" />
</shape>
</item>
<item android:id="#android:id/progress" >
<clip>
<shape>
<corners android:radius="15dp" />
<solid android:color="#color/indigo" />
</shape>
</clip>
</item>
</layer-list>
and it looks like:
Now, the background appears with a round corner, but the progress (inside) is straight, and I want to make it round too, like this:
I googled but didn't find any solution.
Any ideas on how can I achieve this round corner on progress?
Thanks!
you can see example of view here
you can modify the color and size of the thumb and seekbar to do what you want.
This solution was the only way i could do this.
Hope this help
this is my seekbar :
<SeekBar
android:id="#+id/simpleProgressBar"
android:layout_width="fill_parent"
android:layout_height="12dp"
android:max="100"
android:progress="0"
android:background="#null"
android:shape="oval"
android:splitTrack="false"
android:progressDrawable="#drawable/progress_background"
android:secondaryProgress="0"
android:thumbOffset="10dp"
android:thumb="#drawable/oval_seekbar_thumb" />
this is (progress_background.xml) :
<?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:shape="rectangle">
<corners android:radius="5dp" />
<gradient
android:angle="270"
android:endColor="#color/grey_line"
android:startColor="#color/grey_line" />
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape android:shape="oval">
<corners android:radius="5dp" />
<gradient
android:angle="270"
android:endColor="#color/blue"
android:startColor="#color/blue" />
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape android:shape="rectangle">
<corners android:radius="90dp" />
<gradient
android:angle="90"
android:endColor="#color/colorPrimaryDark"
android:startColor="#color/colorPrimary" />
</shape>
</clip>
</item>
and this is the thumb (oval_seekbar_thumb.xml) :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#ffffff" />
<stroke android:color="#color/colorPrimaryDark" android:width="3dp"/>
<size android:height="12dp" android:width="12dp"/>
</shape>
</item>
</selector>
The height of the thumb should be same as the height of the seekbar to look properly.
Replace the <clip> tag with <scale android:scaleWidth="100%">. This should give the curved edges to secondary progress
I know maybe it is obsolete question,but, just remove <clip> tag.

Android progress bar with padding

I want to make my progress bar looks something like that:
I dont want to use images, so I have tried to make this with the shapes:
<item android:id="#android:id/background">
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:centerColor="#2a2723"
android:centerY="0.75"
android:endColor="#2a2723"
android:startColor="#2a2723" />
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:centerColor="#16e61c"
android:centerY="0.75"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</clip>
</item>
But I cant set padding for the green line (Ive tried to set its everywhere where it was possible), and also I can't make such round corners (looks like corners android:radius isn't working). Please help me
<?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>
<solid android:color="#222" />
<corners android:radius="10dp" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<layer-list>
<item>
<color android:color="#00000000" />
</item>
<item
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp">
<shape>
<solid android:color="#00FF00" />
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
</clip>
</item>
</layer-list>
see my blog
A simple workaround is to wrap progress bar into layout which has rounded shape and same background color as progress bar.
Sample progress bar drawable (drawable/progress_bar.xml):
<?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="50dip" />
<solid android:color="#color/white"/>
<padding android:bottom="3dip" android:left="3dip" android:right="3dip" android:top="3dip" />
</shape>
</item>
<item android:id="#android:id/progress">
<bitmap android:src="#drawable/test_progress_bar_progress" android:tileMode="repeat"/>
</item>
</layer-list>
Progress bar style:
<resources>
<style name="ProgressBarStyle" parent="#android:style/Widget.ProgressBar.Horizontal">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">10dip</item>
<item name="android:max">100</item>
<item name="android:progressDrawable">#drawable/progress_bar</item>
</style>
</resources>
Layout shape (drawable/rounded_shape.xml):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<padding android:top="2dip" android:left="2dip" android:right="2dip" android:bottom="2dip"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
<solid android:color="#color/white"/>
</shape>
Activity layout:
<!-- ... -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_shape"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip">
<ProgressBar
android:id="#+id/testSummaryProgressBar"
android:progress="10"
style="#style/ProgressBarStyle"/>
</LinearLayout>
<!-- ... -->
Effect:
To increase padding of progress bar you have to increase padding in rounded_shape file.
Yes it's possible to have exactly that without using image like #Nykakin has suggested. To have the padding and the rounded corner for the progress is to use list-layer for the item progress.
<item android:id="#android:id/progress">
<clip>
<layer-list>
<-- transparent background -->
<item>
<color android:color="#00000000" />
</item>
<-- padding -->
<item
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp">
<shape>
<corners android:radius="50dp" />
<gradient
android:angle="270"
android:endColor="#9dfd6e"
android:startColor="#16e61c" />
</shape>
</item>
</layer-list>
</clip>
Unfortunately I didn't find solution for my problem. The only way I could make round corners was to use rounded 9-pitch image
There is a good tutorial to do that: http://blog.mediarain.com/2011/04/android-custom-progressbar-with-rounded-corners/

Custom horizontal progressbar

Hey,
I just wrote a horizontal progress bar. The progressbar gets this background resource:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/progress_bg" />
</item>
<item android:id="#android:id/progress" android:gravity="center">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
This works fine, but the white progress has the same height as the background. But I want the progress to be smaller than the background of the progress bar, since thre background has a boarder that should not overlap.
Any ideas?
Thanks
There is also :
<item android:id="#android:id/secondaryProgress"></item>
Did you changed it too?
http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
You can try adding android:top, android:left,android:right, and android:bottom to the white progress bar item in order to add padding to the bar.
<item android:id="#android:id/progress" android:gravity="center"
android:top="2dp" android:left="2dp" android:right="2dp" android:bottom="2dp">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
Hi actually I did not use it.
The full xml is:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/progress_bg" />
</item>
<item android:id="#android:id/secondaryProgress" android:gravity="center">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
Cheers
hi try adding stroke that has no color (opacity is max)
I tried this code with my gradient 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>
<corners android:radius="10dip" />
<gradient
android:angle="270"
android:centerColor="#f8d79b"
android:centerY="0.5"
android:endColor="#f8d79b"
android:startColor="#f8d79b" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<stroke
android:width="5px"
android:color="#00ffffff" />
<corners android:radius="10dip" />
<gradient
android:angle="0"
android:endColor="#ffac17"
android:startColor="#ffac17" />
</shape>
</clip>
</item>
</layer-list>
so your code should be like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/progress_bg" />
</item>
<item android:id="#android:id/secondaryProgress" android:gravity="center">
<clip>
<shape>
<stroke
android:width="5px"
android:color="#00ffffff" />
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
worked for me, hope it works for you :D

Categories

Resources