A very tangled title, really do not know how to describe the phenomenon.
Film Bar, first look at what the demand is.
1. Need:?
The video and ticket icons are displayed after the title, and when the title is too long the icon displays to the ellipsis ... After (the TextView ellipsis is displayed, the icon automatically leans back).
2. Problem solving?
Originally is a very normal demand, looks very simple, but did encounter a very egg pain problem, how to do not, blocked for a long time, the following talk about the solution, encounter such problems can be used by friends.
TextView can omit a single line by android:ellipsize= "End" android:singleline= "true",
But when we have the icon followed by the text, the first time to think of LinearLayout layout_weight to do, but the effect is not the same.
Later unexpectedly forget this attribute: Specify the maximum width of the TextView to automatically omit the android:maxwidth= "90DP", plus this resolves.
But the problem is that the value cannot be written as fixed and adapted to the screen. You can calculate the width of the screen, and then dynamically add the value. The code is as follows:
// to calculate the screen width, dynamic display New displaymetrics (); (Activity) mcontext). Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM); int width = dm.widthpixels; -Uiutils.getpixels (Typedvalue.complex_unit_dip, 78));
The PX conversion class used inside is:
Public Static int getpixels (intfloat size) { = resources.getsystem (). Getdisplaymetrics (); return (int) typedvalue.applydimension (Unit, size, metrics); }
When TextView and pictures are displayed in Android, the text ellipsis is displayed, and the picture is automatically on the right.