Textview and picture are displayed together in Android (ellipsis is used for text exceeding, and the picture is automatically on the right)

1、 Requirements:

The title may not be complete enough. Let's take a look at the picture to see what it means. The icons of videos and tickets are displayed after the title. When the title is too long, the icon is displayed after the ellipsis... (textview ellipsis is displayed, and the icon is automatically displayed later).

2、 Problem solving

Textview can realize single line omission through Android: ellipsize = "end" Android: singleline = "true",

But when the icon follows the text, we think of using the layout of LinearLayout for the first time_ Weight, but the effect is different.

Later, I forgot this attribute: specify the maximum width of textview to automatically omit Android: maxwidth = "90dp". Add this to solve it.

However, the problem is that this value can not be written as a fixed value. It should be adapted according to the screen. You can calculate the width of the screen and add values dynamically.

The code is as follows:

The PX conversion classes used are:

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

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