Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3172] Android: Allow setting maxLines property of TextView through Ti.UI.Label

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusClosed
ResolutionDuplicate
Resolution Date2014-04-04T05:36:36.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterAli Gangji
AssigneeRitu Agrawal
Created2014-04-03T20:50:54.000+0000
Updated2016-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.

Comments

  1. Ritu Agrawal 2014-04-03

    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
  2. Ali Gangji 2014-04-04

    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?
  3. Ritu Agrawal 2014-04-23

    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.

JSON Source