Material Designer's low version compatible implementation (12)--slider or SeekBar

Source: Internet
Author: User

Slider, I prefer to call him seekbar, is actually a thing, is to drag the bar. The 5.0 drag bar is completely different from the Holo style on the 4.x and adds some refinement. In addition, a numeric indicator is added to allow users to know where they are when they swipe. Ok, ideal is very good, compatible very cruel! Although I changed a lot of compatibility package itself bug, but still have a big bug not solved-indicator dislocation. When you put a slider in a sliding view, the position of its indicator appears based on where it first appears, meaning that if you scroll it, the indicator will still appear innocently based on its original position, and will not be displayed according to the new position you scroll. What is the reason? In fact, it is very simple, the indicator is a dialog, and the drag bar is completely independent of the control, the indicator display is finished dead, and the drag bar is still. Therefore, if the relationship between the indicator and the drag bar is not handled, there may be a dislocation problem. This I recently see can fix, the wrong position in the Utils.java, everyone can go to repair their own look.

First, import it into their own projects

First, download lib, add support, and write a namespace.

I maintain: https://github.com/shark0017/MaterialDesignLibrary

Original author version: Https://github.com/navasmdc/MaterialDesignLibrary

You can choose a download, I maintain the version may modify the above mentioned misplaced bug, the original author's version does not know will not be fused with my code, the original author's version of the benefits is likely to continue to update, but I see this author is also very lazy, in short, we can learn from each other.

After adding the Lib support, we can use this control, before we put the layout file or write the namespace.

xmlns:app= "Http://schemas.android.com/apk/res-auto"

And then put the control on it.

< Com.gc.materialdesign.views.Slider                 Android:layout_width = "Match_parent"                 android:layout_height= "Wrap_content"                android:layout_gravity= "Center_ Horizontal "                android:layout_marginleft=" 10DP "                Android:layout_ MarginRight= "10DP"/>

It is important to note that the above ball and the actual ball is completely different, I here just for everyone in the compiler preview and get a ball up, just convenient for everyone to see the effect.

Actual effect:

Ii. setting various properties in the layout file

App:shownumberindicator= "true" if the indicator is displayed while sliding

Android:background= "#ff0000" to set the background color, that is, the slider color

App:thumbsize= "30DP" set the size of the sliding sphere, in fact, the size of the ball can be set after holding. But I feel the click to enlarge is to tell the user that you have been holding down the drag ball, with the default will be fully able to achieve this effect, when your ball set larger, the click on the appearance of the magnifying effect will not see (not no, but because the overlay and see), also because your ball is big enough, So there is no need to give the user any instructions. So I didn't do the setup.

App:value= "35" The initial value, if your max is less than your specified value, then the initial direct display of Max values

Three, through the code for various settings, including monitoring events

 Public classSlidertestextendsactionbaractivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.slider); Slider Slider=(Slider) Findviewbyid (R.id.slider); Slider01.shownumberindicator (true);//Display indicator when setting pushSlider.setbackgroundcolor (0xffff0000);//background Color

Slider.setvalue (40);//Set Initial ProgressSlider.setbackgroundcolor (Getresources (). GetColor (R.color.orange));//Background Color//Monitoring ProgressSlider.setonvaluechangedlistener (NewOnvaluechangedlistener () {@Override Public voidOnValueChanged (intvalue) { //TODO Auto-generated method stubsSystem.out.println ("Now value =" +value); } }); Slider.setthumbsize (30);//set the size of the sliderSlider.setvalue (35,false);//set the initial progress in the thread, if true, then the thread is new and may be slower. }}

Four, between the sliding block (discrete slider)

This is actually a segmented slider, this east can refer to the practice in this article ( to do a little change ), suitable for multiple selection of the case. By the way, Google is involved in the indicator is very ugly ah, a drop-shaped really ugly. And for this kind of segmented value of the drag bar, itself is so several values, you come out what indicator ah, completely meaningless.

Article address:http://www.cnblogs.com/tianzhijiexian/p/4044086.html

Material Designer's low version compatible implementation (12)--slider or SeekBar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.