如何使用Appcelerator在水平布局中对齐从右到左的元素?

时间:2016-01-15 06:57:50

标签: appcelerator appcelerator-titanium

使用layout = horizontal,从左侧开始堆叠内的元素。我想从右到左堆叠元素。我怎么能这样做?

2 个答案:

答案 0 :(得分:3)

根据您的使用情况,您也可以这样做:

<Alloy>
    <Window>
        <View layout="horizontal" width="Ti.UI.SIZE" right="0">
            <View backgroundColor="red" left="0" width="20" height="20" />
            <View backgroundColor="green" left="0" width="20" height="20" />
            <View backgroundColor="blue" left="0" width="20" height="20" />
        </View>
    </Window>
</Alloy>

请注意,视图本身不会从右侧堆叠,但通过将父宽度设置为Ti.UI.SIZE,该组作为总计确实对齐。同样,如果您需要视图本身来堆叠RTL并且希望XML中的顺序保持原样,这可能无法满足您的需求。

enter image description here

答案 1 :(得分:2)

没有财产可以做到这一点。但你可以通过镜像技巧来做到这一点。

INDEX.XML

<Alloy>
    <Window class="container" title="Test">
        <View id="holder">
            <View class="item" />
            <View class="item" />
            <View class="item" />
        </View>
    </Window>
</Alloy>

index.tss

"#holder": {
    top:"50dp",
    layout:"horizontal",
    width:Ti.UI.FILL,
    transform:Alloy.Globals.mirror
}
".item":{
    left:0,
    width:"20dp",
    height:"20dp",
    backgroundColor:"red",
    borderColor:"blue",
    borderWidth:"1dp"
}

alloy.js

Alloy.Globals.mirror = Ti.UI.create2DMatrix().scale(-1,1);