Android textview multi text folding and expansion effect

In a recent project, the effect drawing needs to be folded by textview. When the number of lines exceeds a certain number, it will be folded. Click to expand it. I found some effects on the Internet and made some modifications myself. Then use it to share with netizens. Reference: Android UI realizes the folding and unfolding effect of multi line text

The first method is to realize the general steps through multiple layout combinations: - define the layout, vertical linear LinearLayout layout, textview and ImageView. Define basic components in layout- Set the height of textview to the specified number of rows * row height. The reason why MAXLINE is not used is that MAXLINE will control the number of lines of displayed text, which is inconvenient to use animation to expand all contents later. Therefore, the height of textview here should also be wrap_ content。 - Add click events to the whole layout and bind animation. When clicking, if the textview is not expanded, it will expand to its actual height and ImageView will rotate; Otherwise, retract to the specified number of rows * row height, and ImageView rotates and retracts. Layout file:

Core code:

The second method can save a lot of redundant code if it is used in many places: the specific steps are not analyzed directly. Core code:

This class is written in this way. Call to directly reference in the layout file.

Source code download: http://xiazai.jb51.net/201610/yuanma/Androidtextview (jb51.net). rar

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