Android seekbar: drag bar control

Seekbar is an indirect subclass of the horizontal progress bar, which is equivalent to a horizontal progress bar that can be dragged. The following is still a simple example to explain the use of seekbar component. Add a button named "seekbardemo" in the layout file main.xml of the project widgetdemo to start seekbaractivity. Add the following code in main.xml:

Click button and start seekbaractivity. The code is as follows:

At the same time, declare the activity in the androidmanifest.xml file:

<activity android:name=".SeekBarActivity"></activity>

The running effect of seekbaractivity is shown in Figure 1.

The layout file used by seekbaractivity is seekbar.xml, which is as follows:

This file determines that the maximum value of the seekbar object is 100 and the width is the width of the mobile phone screen. The code of seekbaractivity.java is as follows:

The event processing interface of seekbar is onseekbarchangelistener, which provides monitoring for three events: when the drag bar of seekbar starts to be dragged, when the drag bar stops, and when the position of the drag bar changes. Seekbaractivity will print relevant information through logcat when the drag bar is started and stopped. When the position of the drag bar changes, the current value is displayed in the textview.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>