좋은글이 있어서 첨부합니다.
선출처 : http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/
An Android slider (or a SeekBar as it’s called in the Android world) is a pretty slick UI tool which we recently used in our Call Your Folks! app as a means of choosing a reminder frequency between one day and three months.
I’ll walk you through creating a custom-styled seekbar for your Android application using nothing but a few XML and image drawables.
In this tutorial, I assume that you know how to implement a SeekBar in your app; if you don’t, check out the Android API demos, specifically SeekBar1.java and seekbar_1.xml.
Step 1: Create Your Image Drawables (9-Patch)
Before creating any XML drawables, make sure you create the image drawables (including one 9-patch drawable) needed for the seekbar background, handle, and progress sections. The 9-patch drawables will be put to use by the XML drawables in the steps below.
Create the following drawables and place them in your
Step 2: SeekBar Progress Drawable
Now create an XML drawable for the Android seekbar progress (the blue-striped section in the example), call it
seekbar_progress_bg.xml, and place it in your
The above XML first draws a semi-transparent, blue gradient, then layers the semi-transparent stripe image on top of the gradient. The highlighted line of code (line 20) refers to the stripe (semi-transparent) image inside your
drawable folder, created in Step 1.
For more information on creating custom shapes via XML, check out the Android drawable resources docs, specifically the bitmap and shape sections.
Step 3: SeekBar Background Drawable
Next create the main seekbar progress drawable; it’ll assign a drawable to the seekbarprogress and secondaryProgress actions inside your seekbar. Name your drawable something like
seekbar_progress.xml, place it inside your
The first bit of highlighted code above (line 8) is referring to the seekbar background image (9-patch drawable) created in Step 1 and (line 29) is referring to the drawable you created above in Step 2.
Step 4: Bringing it all together…
At this point, all you need to do is call your
seekbar_progress drawable when declaring your seekbar:
The two lines of highlighted code are setting the progress and thumb drawables for the SeekBar item. The
@drawable/seekbar_progress refers to the XML drawable created in the previous step.
See it in action!
For a “live demo” of the seekbar bar being used, download our Call Your Folks! app.
For more information on the Android SeekBar, check out the Android docs.