Android uses textview to achieve scaling effect

During Android development, we often encounter incomplete display of textview.

In this case, the usual processing is:

Scheme 1: add Android: ellipsize attribute to textview, so that the endless parts can be replaced by ellipsis. Scheme 2: textview adopts the riding lamp effect to make it scroll and display all text contents.

For scheme 1, if you want to view the omitted content, how to implement it? Wechat's comment list and pea pod video details have similar use scenarios. Let's take a look at the folding effect of the demo example. The text content is not fully displayed. Instead, use the ellipsis to prompt "more" and the down arrow logo. The screenshot is as follows:

@H_ 404_ 14@

When you click the "more" and the down arrow, all the omitted contents will be displayed, prompting the "more" and the up arrow. The screenshot is as follows:

For the above effects, the realization ideas are as follows:

1. Set textview to display fixed lines by default, such as 3 lines. The content is not displayed completely. Use ellipsis at the end of textview instead.

The contents of the XML file are:

2. When clicking "more" and the down arrow, change the maximum number of lines of textview through the setmaxlines() method of textview. The above effect can be achieved.

The Java code is:

The following is the demo sample download link, textview

That's all for the expansion of textview. If you have a problem, you can leave a message.

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