Horizontal timepicker-With Triangle indicator

Source: Internet
Author: User

 

Transferred fromHttp://www.apkbus.com/

recommended activities: 1. blog writing, recommendation of high-paying jobs, blog writing, sending Xiaomi 2 generations & meizu MX

2. 30 beans for downloading the post

3. follow http://weibo.com/u/2975543812well

The plug-in is complex. First, describe the functions.
1. horizontal scrolling
2. The value can be customized.
3. A triangle indicator is required to point to the current focus
4. The focus changes after clicking, and the triangle indicator can slide to change.
5. Do not disappear when the focus is rolled to the leftmost or rightmost (here, the value of the Focus view is obtained using the new view, and the view in the scroll bar is still rolled out)

Above, imageview is used as the sub-view, and textview is used as the sub-view.

Layout description:
1. The timebar at the bottom of the scroll bar inherits from horizontalscrollview and adds a triangle indicator (Triangle slider) in ondraw () to draw.CodeSo that the indicator slides with the focus.

@ Override public void ondraw (canvas) {super. ondraw (canvas); // log. D ("validated! "," Shocould not always validate "); If (mselectedview! = NULL) {int step = getwidth ()/30; canvas. drawcolor (color. black); paint = new paint (); paint. setantialias (true); paint. setcolor (color. ltgray); paint. setstyle (paint. style. fill); If (curtriangle = NULL) {curtriangle = New Triangle (mselectedview. getleft () + mselectedview. getwidth ()/2-10, mselectedview. gettop ()-4, mselectedview. getleft () + mselectedview. getwidth ()/2 + 10, mselectedview. gettop () + 13.3f);} If (tartriangle = NULL) {tartriangle = New Triangle (mselectedview. getleft () + mselectedview. getwidth ()/2-10, mselectedview. gettop ()-4, mselectedview. getleft () + mselectedview. getwidth ()/2 + 10, mselectedview. gettop () + 13.3f);} If (math. ABS (curtriangle. left-tartriangle. left) <step) {curtriangle. left = tartriangle. left; curtriangle. right = tartriangle. right; curtriangle. redraw ();} If (curtriangle. left> tartriangle. left) {curtriangle. left-= step; curtriangle. right-= step; curtriangle. redraw (); invalidate ();} else if (curtriangle. left <tartriangle. left) {curtriangle. left + = step; curtriangle. right + = step; curtriangle. redraw (); invalidate ();} canvas. drawpath (curtriangle. getpath (), paint );}}}

 

2. add a timepanel to the left and right sides, inherit from linearlayout, reload the ondraw () method, and draw a triangle indicator. This method is simpler than the above Code and does not need to handle slide, draw only the triangle.

@ Override protected void ondraw (canvas) {super. ondraw (canvas); canvas. drawcolor (color. black); paint. setcolor (color. ltgray); paint. setstyle (paint. style. fill); If (curtriangle = NULL) {curtriangle = New Triangle (mtextview. getleft () + mtextview. getwidth ()/2-10, mtextview. gettop ()-4, mtextview. getleft () + mtextview. getwidth ()/2 + 10, mtextview. gettop () + 13.3f);} canvas. drawpath (curtriangle. getpath (), paint );}

 

3. as a container, timepicker holds the timebar and timepanel of the left and right sides. It reloads the ondraw () method and adds the timepanel display and hidden judgment conditions.

@ Override protected void ondraw (canvas) {super. ondraw (canvas); int x = timebar. getscrollx (); focusedbtn = (textview) timebar. getselectedview (); If (focusedbtn! = NULL) {If (focusedbtn. getleft ()-x <0) {(textview) timepanelleft. getchildtextview ()). settext (focusedbtn. gettext (); timepanelleft. setvisibility (view. visible); timepanelright. setvisibility (view. gone);} else if (focusedbtn. getright ()-x> getwidth () {(textview) timepanelright. getchildtextview ()). settext (focusedbtn. gettext (); timepanelright. setvisibility (view. visible); timepanelleft. setvisibility (view. gone);} else {timepanelright. setvisibility (view. gone); timepanelleft. setvisibility (view. gone );}}}

 

4. You still need to reload Dispatchtouchevent  (EV) to pass the click event to the timebar. Otherwise, the timebar cannot respond to the click event.

 
@ Override public Boolean dispatchtouchevent (motionevent eV) {timebar. ontouchevent (EV); return Super. dispatchtouchevent (EV );}

 

Source code: Bottombar.rar

Guangzhou Group 252743081
Android bus Guangzhou super group 218251417
Android Bus Nanjing group 220818530
Android bus Shanghai Group 252742977
Android bus group Shenzhen 252742753 (full)
Android bus Shenzhen group 2 260134856
Android bus Chengdu group 252743807
Android bus Beijing group 111059554 / span>
Android bus Xi'an group 252746034
Android bus Wuhan group 121592153
Android Bus hangzhou group 253603803
Android bus Xiamen group 253604146
Android bus Hunan group 217494504
Android bus Dalian group 253672904
Android bus Qingdao group 257925319

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.