Use of Android SeekBar and Draw9patch

Source: Internet
Author: User

Today to use a SeekBar control, in fact I think the Android default style is very good, but the design does not agree, and SeekBar left and right side also have pictures, the default style and pictures are really uncoordinated, So here you use the picture to customize the SeekBar style, first on the code:

<SeekBarAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:max= "+"Android:thumboffset= "10DP"Android:paddingleft= "10DP"Android:paddingright= "12DP"Android:thumb= "@drawable/device_light_progress_thumb"android:progressdrawable= "@drawable/device_light_progressbar" />
Android:thumb The resource is the slider of the drag bar picture,the role of Android:thumboffset is to prevent the thumb slider can not be fully displayed, to avoid being obscured;
Android:progressdrawable is the style of the custom drag bar, here are two pictures, the code is as follows:
<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android" >        <ItemAndroid:id= "@android: Id/background"android:drawable= "@drawable/progressbar_bg" />             <ItemAndroid:id= "@android: id/progress"android:drawable= "@drawable/progressbar_checked">            </Item>  </layer-list>

Where @android:id/background refers to the picture that the slider bar displays when it is not dragged;

@android: Id/progress refers to the picture shown in the front part of the slider after the slider is dragged;

The use of Seekbar is probably the case, later encountered in this aspect of the problem I will add, the following talk about Draw9patch.

The reason that Draw9patch is because PROGRESSBAR_BG and progressbar_checked two pictures in the configuration of Seekbar, the picture appears too long, the right side of the arc is not finished, and is directly a slice, so you can see the length of the picture does not shrink, The first thing to think about is to use the Draw9patch tool in Sdk-tools to make two images into 9 diagrams, the main process consists of two stages:

First:

Considering that the Seekbar has a smaller scroll bar width of about 5-10 pixels, the first time you make the picture on the horizontal, it can be stretched and shrunk and not processed vertically. Import the picture drawable-h, after debugging found that the picture in the top of the black edge, and the right side of the picture is cut, you can know that the picture is still not shrinking;

After looking for information, found that they did not understand the Draw9patch production 9 diagram of the mechanism, that is, the upper and lower constraints are what:

The left is the area that can be scaled vertically.
The top is the area where the horizontal direction can be scaled.
The right side is a vertically oriented content area.
Below is the horizontal content area

(bottom and right padding values for picture content)

The constraint must be both high and wide, and if only the height or width of the constraint is added, there will still be a black line.

In addition, when the black line is set, the point cannot be broken, otherwise the 9patch image will be displayed according to the normal picture.

After figuring out the principle, the longitudinal also carries on the Draw9patch processing, after debugging, Seekbar the right side also displays the arc, namely the picture is suitable to match the normal.

Second:

Then I will progressbar_checked this picture also carried out the same processing, that is, drag the slider after the picture is also made into 9 charts. When you import an app, the display of the Seekbar error, that is, when the slider is not dragged, the entire seekbar is already displayed as a progressbar_checked picture style, as if it had been dragged. I do not understand this error, Progressbar_checked.png is not changed to 9 graph when the normal display, changed to 9 after the error, after the progressbar_checked replaced with the original picture, the application is back to normal.

The guess here is the result of the 9 auto-adaptation controls, which need to be studied for specific reasons.

Use of Android SeekBar and Draw9patch

Related Article

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.