Seekbar Summary of Android (i)

Source: Internet
Author: User

2015-04-24

SeekBar:

A special progress bar that contains a slider to adjust the progress value.

the directory structure in the API is as follows:

Contains several special properties:

1:max: Sets the maximum value of the progress bar. Corresponding method: Setmax (int max); max=100, representing its value range is 0-100, a total of 101 values;

2: Progress: Set default progress value pair due method: setprogress (int progress);

3:secondaryprogresss: Set the default buffer value corresponding to the method setsecondaryprogress (int secondaryprogresss);

The above methods and members are inherited from ProgressBar, while the special attributes of SeekBar are as follows :

4:thumb : Slider attribute, should correspond to be a drawable resource;

5:progressdrawable, representing SeekBar background Image

6:theSeekBar class contains a setonseekbarchangelistener method. This method is triggered when the user is using seekBar , and is typically used to set the listener event

Seekbar.onseekbarchangelistener: is a public static interface . Three methods are included:

The user must implement the methods in the interface or use an anonymous inner class.

Two: User-defined SeekBar style:

When the current SeekBar does not meet the needs of the user, we can customize the SeekBar to achieve the desired functionality and visual experience.

Simple Customization : Customize in XML , You can implement different background graphs and sliders, so that the SeekBar UI experience better.

Complex customization : Rewrite the myseekbar code with Java code extends SeekBar; can give Myseekbar add some controls and features.

First look at the simple implementation :

Custom SeekBar sliders are defined as:android:thumb= "@drawable/thumb_bar".

At this point you need to customize a thumb_bar.xml under the res/drawable file

It calls the contents of the thumb_bar.xml as follows

<?xml version= "1.0" encoding= "UTF-8"?>

<selectoR xmlns:android= "Http://schemas.android.com/apk/res/android" >

<!--Press status --

<item android:state_pressed="true"

android:drawable= "@drawable/thumb_dn"/>

<!--Focus State --

<item android:state_focused= "true"

android:drawable= "@drawable/thumb_up"/>

<!--default state --

<item android:drawable= "@drawable/thumb_up"/>

</selector>

Note: The above code source is online

Note the Selector markers and status markers in the diagram. The Selector can be used to select different images in different states, such as when the user presses, with A photo, not on time with B photos.

Customizing the implementation of the SeekBar background map :android:progressdrawable= "@drawable/bg_bar".

is similar to a custom slider implementation: It references an XML file in a property , and then customizes the picture in the XML file.

<?xml version= "1.0" encoding= "Utf-8"?>

<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" >

<!-- background map --

<item android:id= "@+android:id/background" android:drawable= "@drawable/bar_dn"/>

<!-- Second progress map --

<item android:id= "@+android:id/secondaryprogress" android:drawable= "@drawable/bar_dn"/>

<!-- Progress --

<item android:id= "@+android:id/progress" android:drawable= "@drawable/bar_up"/>

</layer-list>

===============================================================

Tags : layer-list:layer-list can cascade multiple images in order. The Item has two important XML attributes:android:ID and Android : drawable property.

Note: Picture resources; Source Network

The final results are shown below:

Seekbar Summary of Android (i)

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.