Detailed explanation of Android custom indicator timeline effect example code

The indicator timeline is often used in takeout and shopping apps. The effect is probably like the following. After reading many online articles, most of them are drawn by themselves, which is too troublesome. In fact, it can be realized through listview.

In the layout file associated with activity_ Place a listview in main.xml. The code is as follows. Since this list is only used to display information and does not require users to click, set its clickable attribute to false; In order to eliminate the ripple effect caused by listview clicking, we set the value of listselector property to transparent; We don't need split lines between list items, so set the value of its divider property to null.

activity_ main

Layout of each list item stepview_ Adapter.xml, the code is as follows. Since the points and lines of the timeline are located in the item layout, in order to make the lines continuous, set the dividerheight property value of the listview above to 0dp, that is, each list item in the vertical direction is next to each other. In the layout of item, we first use LinearLayout to divide the layout into left and right parts. The layout of timeline is on the left and the layout of content is on the right.

The content layout and logistics information is a relativelayout. In order not to make the text of two list items too close, set its paddingbottom and paddingtop properties in relativelayout.

The layout of the timeline is also a relativelayout. In order to align the dots of the timeline with the text displaying time, we need to place a vertical line above the dots, so the overall layout is line point line. In order to align the line with the center of the dot, we center the line and the dot horizontally, that is, Android: layout_ centerHorizontal="true"

stepview_ adapter

Define an adapter with the following code. Since the display form of the logistics information in the first row is different from others, it should be noted that the top line in the timeline layout of the item in the first row is not displayed

In order to see the effect of the layout, simulate some false data in the activity. An entity class trace needs to be defined. It has two properties, accepttime and acceptstation. The code is as follows:

StepViewBean

MainActivity 

GitHub address: https://github.com/peiniwan/StepView

summary

The above is a detailed explanation of the example code of Android custom indicator timeline effect introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>