2016-05-13 117 views
0

考虑下面的XML:在XML中设置的NativeScript zIndex无法正常工作?

<Page xmlns="http://schemas.nativescript.org/tns.xsd" > 
    <!-- UI Decalration --> 
    <AbsoluteLayout> 
     <GridLayout zIndex="99" height="100" width="100" backgroundColor="red"></GridLayout> 
     <GridLayout zIndex="1" height="200" width="200" backgroundColor="green"></GridLayout> 
    </AbsoluteLayout> 
</Page> 

在我的理解中的红色方块应该是可见的,但它的背后隐藏着绿色的。难道我做错了什么?

+0

只需更改gridLayouts的顺序,然后最后一个元素将位于顶部。也许你可以在style/css中设置z-index? –

+1

请注意,此时z-index仅在Android API级别21支持。 http://docs.nativescript.org/angular/ui/styling.html#supported-css-properties –

回答

1

将z-index声明为CSS属性,以便所有元素都应该呈现为预期的。 例如:

page.css

.lower-grid { 
    z-index: 1; 
} 
.upper-grid { 
    z-index: 99; 
} 

page.xml

<AbsoluteLayout> 
     <GridLayout class="upper-grid" height="100" width="100" backgroundColor="red" /> 
     <GridLayout class="lower-grid" height="200" width="200" backgroundColor="green" /> 
    </AbsoluteLayout> 

该解决方案制定了我 - 记住,z-index的是支持Android API 21以上。

+0

好吧,我编辑我的问题,不要混淆人。 CSS属性确实有效。所以,我给你一个投票。我感兴趣的是为什么javascript属性不起作用。 – terreb

+1

这是一个我刚才在https://github.com/NativeScript/NativeScript/issues报告并且已经计划修复的bug。 –