Vertical seekbar of Android UI and alignment of custom background and thumb (think differently)

Source: Internet
Author: User

This problem really hurts. There are also a group of articles on the Internet. All of them are simple and useless, and they are full of loopholes. A new custom will cause problems. A little tangle.

Prerequisites: Save trouble and speed;

PS: I have good Java skills, but it is only a month before I do Android. The project does not have time for you to study seekbar carefully.
How to draw, or completely rewrite one, instead of rotating this group online for 90 °. It is undeniable that I also use this method, because I don't want to put all the logic in the Code for implementation, because the other method will come faster, the following shows how I solve the problem. I just want to end this thing quickly, and then I can really get into touch with something that is content, instead of simply staying at the Android Application layer. This should be done.
With access to JNI, the core logic is implemented in C. We look forward to the OK solution.

Let's take a look at my demo:



Use the pad test program, horizontal screen.

The entire work code is attached to the download link below, so you can skip the download and use it immediately.

The code is small to explain, and the demo is directly down on the Internet, because there is no need to rewrite it on your own, wasting your youth. I added a backup function for adjusting the start position of the custom thumb and commented out it in the code, the default value is thumb below, and the start position is 0 at the bottom. You need to adjust the value to the above and use the annotated function tracktouchevent, and the two lines commented out in ondraw.

Then there is the core of the problem. It is normal to simply set the background color and use the default thumb display. However, a user-defined process may cause various unpleasant things, such as being overwritten, incorrect, and so on. The various adjustment schemes on the Internet are perfect for the horizontal seekbar, but the vertical bar is tangled. Because only the progress bar and thumb and the data obtained by the event are converted, the original seekbar is inherited from the system in a horizontal manner, such as the wide and high control of the background, if there are also rewriting, it may take some time. I don't want to do this. I guess you don't want to do it either.

I found a message online and did not have any related article. Finally, I pushed all the questions to the image. That is to say, since it is not correct, I will align according to the current alignment, and show the user only the UI, the UI just draws the image. So I don't need code to solve it. With images, I add about 5 more transparent pixels to the background image of seekbar (if it is a PNG Image ). Alignment must be based on the boundary alignment of the image. The enlarged pixels are filled with the ugly alignment, OK, perfect display, and no offset, because you can also use Android: paddingtop = "1dip" for simple control and can be adjusted to meet simple requirements.

Other questions:

Q: Someone may ask, "how is my background stuck ?", Because the code converts it to 90 ° ~ Dear user. At this time, the problem arises again. "How can I turn it back ?".

A: The Little childishness of programmers is accustomed to using code to solve problems. Even if it is just like the South, even if it is around the curve, it is still in the program where your thoughts are located. What I want to say is that you ask the artist to help you rotate the image for 90 °, which is also a shortcut key in PS, which may take less than 1 s, however, you are holding the program in mind what logic you want to use to prevent the background from rotating with seekbar. After half a day, you still have no solution. Do you understand what I mean?

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

Q ?!

A: Haha, bingo. Correct. The UI is pieced together. If you still want to implement it with code, you will only be one of two types: 1. It may be a perfect geek. 2. You do not understand the true meaning of the front-end UI. The interface is originally a lie. It creates an illusion of manipulation, completes a series of manipulation actions, and feedbacks the state of the program.

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

The idea is as follows:

Someone asked me on the internet that my seekbar set Android: thumboffset = "0dip" to prevent thumb from being overwritten at both ends ", but why can't I drag thumb to the top of both ends? Well, the starting point is this. After this attribute is set, the two ends are aligned based on the boundary of the image. Generally, thumb is circular or similar, and transparent pixels are left when the foreground is used as an image, in this way, transparent pixels also occupy the alignment space, giving users the feeling that they have not reached the top and the world has been aligned.

Since the pure picture problem can make your program imperfect, it can also make your program perfect, depending on how you think.

OK. Continue to work until now.


Download demo ....

Download the current document DOC .. Reprinted to indicate the source ....

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.