【问题标题】:Titanium mobile Alloy: fraction view size in *.tss or *.xml钛合金移动合金:*.tss 或 *.xml 中的部分视图大小
【发布时间】:2014-06-28 15:31:43
【问题描述】:

我有一个里面有七个视图的容器:

<View class="container>
    <Button class="day"/>
    <Button class="day"/>
    <Button class="day"/>
    <Button class="day"/>
    <Button class="day"/>
    <Button class="day"/>
    <Button class="day"/>
</View>

是否可以在不使用 postlayout 事件的情况下将按钮的宽度设置为 *.tss 或 *.xml 中容器宽度的 1/7?对于四个视图,我可以简单地指定25%,但是对于七个视图宽度之和,14.285714285% 会变得超过 100%。

【问题讨论】:

    标签: titanium titanium-mobile titanium-alloy


    【解决方案1】:

    它变得超过 100% 的原因是因为floating point math is funky。此外,为了复合这一点,我认为 Titanium 会在代码中四舍五入这些百分比(只是推测)。

    为简单起见,请尝试将百分比保留为整数,如下所示:

    ".day" : {
        width : "14%"
    }
    
    <View class="container" layout="horizontal">
        <Button class="day"/>
        <Button class="day"/>
        <Button class="day"/>
        <Button class="day"/>
        <Button class="day"/>
        <Button class="day"/>
        <Button class="day"/>
    </View>
    

    “14.2%”或许也能逃脱惩罚,因为它没有那么多有效数字。

    【讨论】:

    • 此解决方案将无法正常工作。取决于父级的宽度,它可能会导致像素错位,并且不会填满整个视图的宽度。
    • @0101 问题的关键是视图大小取决于父级的宽度。这很好用,可以填满 99.4% 的容器。
    • 如果你认为这已经足够好了,那么好吧......但很抱歉我不能同意你的观点。
    • 那你有什么建议?
    • 我想发布我的解决方案,但直到我没有来自@farwayer 的所有详细信息,我才能发布
    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多