Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1729] Android: Setting zIndex fails on Views

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-11-05T13:38:12.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sSprint 2011-37, Release 1.8.0
ComponentsAndroid
Labelsn/a
ReporterDon Thorp
AssigneeNatalie Huynh
Created2011-04-15T03:00:42.000+0000
Updated2011-11-05T13:38:12.000+0000

Description

When zIndex is passed as a creation argument it works. Runtime does not. It looks like there might be a setZIndex method that's in the way.

Comments

  1. hal 2011-04-15

    In the latest build, changing the zindex at runtime actually causes an exception.

  2. Eduardo Gomez 2011-07-25

    Associated HD ticket

    http://appc.me/c/APP-764736

    Environment

    {noformat} Product: Mobile Titanium SDK: Mobile 1.7.1 Platform OS: Android Platform OS Version: 2.2 {noformat}

    Console Log output

    {panel} 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): (main) [241,422] Sending event: exception on thread: main msg:java.lang.NumberFormatException: unable to parse '1.0' as integer; Titanium 1.7.1,2011/06/13 15:34,4a68cc... 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): java.lang.NumberFormatException: unable to parse '1.0' as integer 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at java.lang.Integer.parse(Integer.java:433) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at java.lang.Integer.parseInt(Integer.java:422) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at java.lang.Integer.parseInt(Integer.java:382) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at org.appcelerator.titanium.util.TiConvert.toInt(TiConvert.java:253) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at org.appcelerator.titanium.view.TiUIView.propertyChanged(TiUIView.java:325) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at org.appcelerator.kroll.KrollPropertyChange.fireEvent(KrollPropertyChange.java:21) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:487) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:272) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at android.os.Handler.dispatchMessage(Handler.java:95) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at android.os.Looper.loop(Looper.java:123) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at java.lang.reflect.Method.invokeNative(Native Method) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at java.lang.reflect.Method.invoke(Method.java:521) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-23 08:18:01.658: ERROR/TiUncaughtHandler(1143): at dalvik.system.NativeStart.main(Native Method) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): FATAL EXCEPTION: main 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): java.lang.NumberFormatException: unable to parse '1.0' as integer 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at java.lang.Integer.parse(Integer.java:433) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at java.lang.Integer.parseInt(Integer.java:422) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at java.lang.Integer.parseInt(Integer.java:382) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at org.appcelerator.titanium.util.TiConvert.toInt(TiConvert.java:253) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at org.appcelerator.titanium.view.TiUIView.propertyChanged(TiUIView.java:325) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at org.appcelerator.kroll.KrollPropertyChange.fireEvent(KrollPropertyChange.java:21) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:487) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:272) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at android.os.Handler.dispatchMessage(Handler.java:95) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at android.os.Looper.loop(Looper.java:123) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at java.lang.reflect.Method.invokeNative(Native Method) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at java.lang.reflect.Method.invoke(Method.java:521) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-23 08:18:01.918: ERROR/AndroidRuntime(1143): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) {panel}

    Workaround

    Set an index value to establish the position relative to other sibling views within an event listener.
       var win = Ti.UI.createWindow({
       	backgroundColor:'white'
       });
       
       var scrollView = Ti.UI.createScrollView({height:200,top:0});
       win.add(scrollView);
       
       var myLastIndex = 9;
       
       var view1 = Ti.UI.createView({
       	backgroundColor:'pink',
       	zIndex: myLastIndex++,
       	width:200,
       	height:30,
       	top:10,
       	left:10
       });
       
       var view2 = Ti.UI.createView({
       	backgroundColor:'blue',
       	zIndex:myLastIndex++,
       	width:200,
       	height:30,
       	top:15,
       	left:15
       });
       
       var view3 = Ti.UI.createView({
       	backgroundColor:'red',
       	zIndex:myLastIndex++,
       	width:200,
       	height:30,
       	top:20,
       	left:20
       });
       
       scrollView.add(view3);
       scrollView.add(view2);
       scrollView.add(view1);
       
       var l = Ti.UI.createLabel({
       	text:'scroll view: red on top, blue in the middle, pink below, Click the RED one to sit on top the YELLOW one',
       	color:'#777',
       	width:300,
       	height:30,
       	top:50,
       	left:10,
       	font:{fontSize:12}
       });
       scrollView.add(l);
       
       view3.addEventListener('click',function()
       {	
       	var newView = Ti.UI.createView({
       		backgroundColor:parseInt ('#ff'+myLastIndex),
       		zIndex: myLastIndex++,	
       			width:200,
       			height:30,
       			top: 25,
       			left:25
       	});
       	
       	win.add(newView);
       	Ti.API.info('setting zIndex'+myLastIndex);
       });
       
       win.open();
       
  3. Don Thorp 2011-09-12

    Test code for dynamic zIndex changes
       var win = Ti.UI.createWindow({
       	backgroundColor:'white'
       });
       
       var myLastIndex = 3;
       
       var view1 = Ti.UI.createView({
       	backgroundColor:'yellow',
       	zIndex: 1,
       	width:200,
       	height:50,
       	top:10,
       	left:10
       });
       
       var view2 = Ti.UI.createView({
       	backgroundColor:'blue',
       	zIndex:2,
       	width:200,
       	height:50,
       	top:35,
       	left:15
       });
       
       var view3 = Ti.UI.createView({
       	backgroundColor:'red',
       	zIndex:myLastIndex++,
       	width:200,
       	height:50,
       	top:60,
       	left:20
       });
       
       win.add(view3);
       win.add(view2);
       win.add(view1);
       
       var l = Ti.UI.createLabel({
       	text:'scroll view: red on top, blue in the middle, yellow below, Click the RED one to bring YELLOW forward. Click the YELLOW one to send it back.',
       	color:'#777',
       	width:300,
       	height:60,
       	top:150,
       	left:10,
       	font:{fontSize:12}
       });
       win.add(l);
       
       view1.addEventListener('click', function() {
       	if (view1.zIndex != 1) {
       		view1.setZIndex(1);
       	}
       });
       
       view3.addEventListener('click',function() {	
       	view1.zIndex = myLastIndex++;
       });
       
       win.open();
       
  4. Natalie Huynh 2011-09-14

    Tested with 1.8.0.v20110914092150 on Nexus S 2.3.4 Hero 2.1 Gslate 3.1
  5. Don Thorp 2011-11-05

    Fixing labels.

JSON Source