0

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

4

2 回答 2

4

根据您的用例,您还可以执行以下操作:

<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 中的顺序保持原样,这可能无法满足您的需求。

在此处输入图像描述

于 2016-01-16T11:00:46.897 回答
3

没有属性可以做到这一点。但是你可以通过镜像技巧来做到这一点。

索引.xml

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

索引.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"
}

合金.js

Alloy.Globals.mirror = Ti.UI.create2DMatrix().scale(-1,1); 
于 2016-01-15T08:21:52.403 回答