Rangebar is a seekbar with a range of options. Using this project is actually very simple. Is a custom control ~
I. layout files
We can see that many attributes can be customized, and can be defined in Java code in addition to XML.
Note:
<Declare-styleable name = "rangebar"> tickcount: Number of split lines tickheight: height of the split line barweight: width of the split line and sliding bar barcolor: The color of the split line and sliding bar connectinglineweight: connectinglinecolor: the slider color (excluding the slider) of the selected area. thumbradius: radius of the slider. In fact, it is to change the size of the slider. thumbimagenormal: thumbimagepressed: thumbcolornormal: Color of the normal status of the slider thumbcolorpressed: color of the slider when it is pressed <ATTR name = "tickcount" format = "integer"/> <ATTR name = "tickheight" format = "dimension"/> <ATTR name = "barweight" format = "dimension"/> <ATTR name = "barcolor" format = "reference | color"/> <ATTR name = "connectinglineweight" format = "dimension"/> <ATTR name = "connectinglinecolor" format = "reference | color"/> <ATTR name = "thumbradius" format = "dimension"/> <ATTR name = "thumbimagenormal" format = "Reference "/> <ATTR name = "thumbimagepressed" format = "Reference"/> <ATTR name = "thumbcolornormal" format = "reference | color"/> <ATTR name = "thumbcolorpressed" format = "Reference | color"/> </declare-styleable>
Activity_main.xml
<Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: Tools = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "match_parent" tools: context = "$ {relativepackage }. $ {activityclass} "><! -- You can use XML to configure the custom namespace custom. The specific configuration attributes can be seen at the bottom --> <COM. edmodo. rangebar. rangebar xmlns: Custom = "http://schemas.android.com/apk/res-auto" Android: Id = "@ + ID/rangebar" Android: layout_width = "match_parent" Android: layout_height = "wrap_content" Android: layout_marginbottom = "50dp" Android: layout_margintop = "50dp" custom: tickcount = "7"/> </relativelayout>
Java code:
Package COM. kale. rangbartest; import COM. edmodo. rangebar. rangebar; import COM. edmodo. rangebar. rangebar. onrangebarchangelistener; import android. app. activity; import android. graphics. color; import android. OS. bundle; public class mainactivity extends activity {rangebar; @ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activ Ity_main); rangebar = (rangebar) findviewbyid (R. id. rangebar); rangebar. settickcount (7); // The number of split lines rangebar. settickheight (25); // The height of the split line rangebar. setbarweight (6); // width of the split line and slide bar rangebar. setbarcolor (0xff000000); // split line and slider color, rangebar. setconnectinglineweight (5); // set the rangebar width of the selected area. setconnectinglinecolor (color. parsecolor ("# ff0000"); // The rangebar color of the selected area. setthumbimagenormal (R. drawable. thumb); // The image R displayed when the slider is normal. Angebar. setthumbimagepressed (R. drawable. ic_launcher); // The image displayed when the slider is pressed/*** if setthumbradius (), setthumbcolornormal (), setthumbcolorpressed () if one or more of them are set, rangbar will automatically ignore the configured slider image. This is worth noting !!! * /// Rangebar. setthumbradius (20); // the slider radius (> 0), that is, the size of the slider. You can use setthumbradius (-1) to bring it back to the default state. // you can set the color of the normal state of the slider. This will overwrite the setting of setthumbimagenormal, if you want to restore the original image, you can setthumbcolornormal (-1) // rangebar. setthumbcolornormal (color. parsecolor ("# 0000ff"); // sets the color of the normal status of the slider, which overwrites the setthumbimagepressed setting. If you want to restore the original format, you can setthumbcolorpressed (-1) // rangebar. setthumbcolorpressed (color. parsecolor ("#00ff00"); rangebar. setthumbindices (1, 5); // you can specify the position of the slider to the left. Set the left slider to a grid on the left and the right slider to five grids on the left. // set the listener rangebar. setonrangebarchangelistener (New myrangbarlistener ();}/*** @ Author: Jack Tony * @ tips: Listener selected by the listener slider * @ Date: 2014-10-22 */private class myrangbarlistener implements onrangebarchangelistener {/*** three parameters: * 1. rangbar object * 2. the distance between the slider on the left and the left. The distance here is replaced by each grid * 3. the distance between the slider on the right and the left is replaced by the number of cells on the slider * You must note that the Left = 2 parameter indicates that the slider on the left is at the third split line. ** Example: * leftthumbindex = 2; rightthumbindex = 5; ** thumb slider this is the left and right slider * | ---- | the Shard is the split line */@ override public void onindexchangelistener (rangebar, int leftthumbindex, int rightthumbindex) {system. out. println ("leftthumbindex =" + leftthumbindex + "rightthumbindex =" + rightthumbindex );}}}
Note:If setthumbradius (), setthumbcolornormal (), setthumbcolorpressed () contains one or moreWhen this parameter is set, rangbar automatically ignores the configured slider image. This is worth noting !!!
:
Attribute comparison table:
Source: https://github.com/edmodo/range-bar/wiki
Source code download: http://download.csdn.net/detail/shark0017/8069581
Use the open-source project rangbar to implement the existing seekbar