First, the demand:
The title may not write enough, the next look at the picture, we will understand what is meant. The video and ticket icon is followed by the title, and when the title is too long, icon displays to the ellipsis ... After (the TextView ellipsis is displayed, the icon automatically leans back).
Ii. Problem-solving
TextView can be android:ellipsize="end" android:singleLine="true"
omitted by implementing a single line,
But when we have the icon to follow the text behind, the first time LinearLayout
to think of the use of layout_weight
to do, but the effect is not the same.
Later forgot this attribute: The specified TextView
maximum width is automatically omitted android:maxWidth="90dp"
, plus this is resolved.
But the problem is, this value cannot be written in a fixed order and should be adapted to the screen. You can calculate the width of the screen, and then add the values dynamically.
The code is as follows:
To calculate the screen width, dynamic display
displaymetrics DM = new Displaymetrics ();
(activity) mcontext). Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
int width = dm.widthpixels;
Holder.tv_postbar_item_title.setMaxWidth (Width-uiutils.getpixels (Typedvalue.complex_unit_dip, 78));
The PX conversion classes used inside are:
public static int getpixels (int unit, float size) {
Displaymetrics metrics = Resources.getsystem (). getdisplaymetrics ();
return (int) typedvalue.applydimension (unit, size, metrics);
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.