[AC-3172] Android: Allow setting maxLines property of TextView through Ti.UI.Label
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | n/a |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2014-04-04T05:36:36.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Ali Gangji |
Assignee | Ritu Agrawal |
Created | 2014-04-03T20:50:54.000+0000 |
Updated | 2016-03-08T07:57:34.000+0000 |
Description
The 'ellipsize' property for labels does not work on Android 4.x because maxLines cannot be set on the underlying TextView.
For example:
var win1 = Titanium.UI.createWindow({
backgroundColor:'red',
exitOnClose:true,
title:'win1: Main Window'
});
var label1 = Ti.UI.createLabel({
backgroundColor:'black',
color:'white',
ellipsize:true,
text:'This is some text to demonstrate the use of the ellipsize property of a label(click me!) This is some text to demonstrate the use of the ellipsize property of a label(click me!)',
height:66,
width:200,
font:{fontSize:16}
});
win1.add(label1);
win1.open();
The above will be ellipsized on iOS and on Android 2.x, but not on Android 4.0 or higher.
We can make this work by a simple modification to the TiUILabel class to allow setting the 'maxLines' property of the TextView which is wrapped by TiUILabel.
This is a really old Android platform bug that is still not fixed. We cannot work around it in the Titanium. Resolving it as a duplicate of TIMOB-10451. Google bug: http://code.google.com/p/android/issues/detail?id=882
This is not the same issue. The android bug you referenced is an issue with single-line text and the ellipsize property. The way to ellipsize text after multiple lines on android is to use the maxLines property. This is a feature request to implement that property to enable setting a specific number of lines greater than 1. This is new functionality that titanium does not support. Why would you not have interest in supporting this property?
As per engineering comment in TIMOB-10451 ticket, we cannot set maxLines as SDK would need to calculate maximum number of lines dynamically based on a number of variables including font, spacing, text size and To set the maxLines, the number of lines needs to be calculated dynamically which really depends on the font, spacing, text etc. and that would be error prone at the SDK level.