I had recently come across the need for a vertical progress bar but is unable to find a solution using the existing Progr ESS Bar widget. The solutions I came across generally required an extension of the current Progress Bar or a completely new class in it SE Lf. I wasn ' t convinced rolling out a new class to achieve a simple orientation change was necessary.
This article presents a simple, elegant, and most importantly, a no-hack solution to achieving a vertical progress bar. I ' m going to skip the explanation and simply provide a cookie cutter solution. If you require further details feel free to contact me or leave a comment below.
Create an XML in your drawable folder (not drawable-hdpi or drawable-mdpi – place it in drawable). For the example I call my XML vertical_progress_bar.xml
Here's what to place in the XML file:
<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android"> <ItemAndroid:id= "@android: Id/background"> <Shape> <CornersAndroid:radius= "5dip" /> <GradientAndroid:startcolor= "#ff9d9e9d"Android:centercolor= "#ff5a5d5a"Android:centery= "0.75"Android:endcolor= "#ff747674"Android:angle= " the" /> </Shape> </Item> <ItemAndroid:id= "@android: id/secondaryprogress"> <Clipandroid:cliporientation= "vertical"android:gravity= "Bottom"> <Shape> <CornersAndroid:radius= "5dip" /> <GradientAndroid:startcolor= "#80ffd300"Android:centercolor= "#80ffb600"Android:centery= "0.75"Android:endcolor= "#a0ffcb00"Android:angle= " the" /> </Shape> </Clip> </Item> <ItemAndroid:id= "@android: id/progress"> <Clipandroid:cliporientation= "vertical"android:gravity= "Bottom"> <Shape> <CornersAndroid:radius= "5dip" /> <GradientAndroid:startcolor= "#ffffd300"Android:centercolor= "#ffffb600"Android:centery= "0.75"Android:endcolor= "#ffffcb00"Android:angle= " the" /> </Shape> </Clip></Item>
Create an XML file called Styles.xml and place it in res/values. If your project already contains styles.xml in res/values then skip this step.
Modify your Styles.xml file and append the following code to the end of the file:
<stylename= "Widget"></style><stylename= "Widget.progressbar"> <Itemname= "Android:indeterminateonly">True</Item> <Itemname= "Android:indeterminatebehavior">Repeat</Item> <Itemname= "Android:indeterminateduration">3500</Item> <Itemname= "Android:minwidth">48dip</Item> <Itemname= "Android:maxwidth">48dip</Item> <Itemname= "Android:minheight">48dip</Item> <Itemname= "Android:maxheight">48dip</Item></style><stylename= "Widget.ProgressBar.Vertical"> <Itemname= "Android:indeterminateonly">False</Item> <Itemname= "Android:progressdrawable">@drawable/progress_bar_vertical</Item> <Itemname= "Android:indeterminatedrawable">@android:d Rawable/progress_indeterminate_horizontal</Item> <Itemname= "Android:minwidth">1dip</Item> <Itemname= "Android:maxwidth">12dip</Item></style>
Add your new vertical progress bar to your layout. Here's an example:
< ProgressBar Android:id = "@+id/vertical_progressbar" android:layout_width= "12dip" android:layout_height= "300dip" style= "@style/widget.progressbar.vertical"/>
That should is all need to does to make use of a vertical progress bar in your project. Optionally, you might has custom drawable Nine-patch images that is using for the progress bar. You should make the appropriate changes in the Progress_bar_vertical.xml file. I hope this helps your out in your project!
by Jagsaund from http://stackoverflow.com
Original address: Http://stackoverflow.com/questions/3926395/android-set-a-progressbar-to-be-a-vertical-bar-instead-of-horizontal
The solution is better, and the individual thinks it's better to rewrite a vertical class than yourself, because when I use a rotated rewrite class, I find that some of the phones can't be expected to display.
Android to achieve vertical ProgressBar