Android custom view realizes vertical timeline layout

Timeline, as the name suggests, lists the events in chronological order, bringing a more intuitive experience to users. The logistics sequence of jd.com and Taobao is a timeline, which must be familiar to everyone, as shown in the following figure:

analysis

One of the most common ways to implement this is to use listview. Here, I implement it by inheriting LinearLayout. First, some custom attributes are defined:

attrs.xml

TimelineLayout.java

As can be seen from the above code, it is drawn in three steps: first draw the start solid circle, then draw the end icon, then draw a line between the start and end, and then draw the solid circle of each step on the line. activity_ main.xml

MainActivity.java

item_ timeline.xml

Attach the tool class for pixel conversion:

The renderings are as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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