【问题标题】:Titanium: Animate an element in a ListItem/ ListViewTitanium:为 ListItem/ListView 中的元素设置动画
【发布时间】:2017-04-15 20:03:01
【问题描述】:

我想为 ListItem 中的元素设置动画

例如,考虑以下简单的ListView

<ListView>
    <Templates>
        <ItemTemplate name="foo">
            <View layout="vertical">
                <Label color="red" id="label" bindId="bExampleLabel"/>
                <Button onClick="onClickButton">Click Me to make the label go blue</Button>
            </View>
        </ItemTemplate>
    </Templates>

    <ListSection id="exampleListSection">
        <ListItem template="foo" bExampleLabel:text="Example 1"></ListItem>
        <ListItem template="foo" bExampleLabel:text="Example 2"></ListItem>
    </ListSection
</ListView>

以及以下脚本:

function onClickButton(e) {
    var item = $.exampleListSection.getItemAt(e.itemIndex);
    item.bExampleLabel = {
        color: 'blue'
    };
    $.exampleListSection.updateItemAt(e.itemIndex, item);
}

上面的 XML 代码只有一个 ListView,其中包含 2 个 ListItem,每个 ListItem 包含一个标签和一个按钮。当您单击按钮时,它会使标签变为蓝色。

但我希望它动画它变成蓝色。

通常这样做是这样的:

$.elementId.animate({
    color: 'blue'
});

但是,我不知道如何在 ListItem 的上下文中执行此操作,因为您似乎无法直接访问这些对象。

【问题讨论】:

    标签: titanium appcelerator appcelerator-titanium titanium-alloy appcelerator-alloy


    【解决方案1】:

    您不能在 listView 中为 ListItem 设置动画,您只能更改使用 bindId 访问的项目属性

    模板:字典

    包含将样式名称(键)映射到 ItemTemplate(值)的键值对。 一旦打开窗口,此属性就无法更改。

    如果你想在列表中设置动画使用 TableView,你可以用 TableViewRow 做你想做的事

    【讨论】:

    • 无论如何至少可以直接与对象交互吗?使用 require 语句怎么样?
    • 我刚刚发现你不能有一个require语句。但是还是不能直接访问元素吗?
    • 是的,您不能在 ListView 中使用 require 语句,您只能访问由 getItemAt 或 ListView.data[sectionId][itemId] 返回的项目。
    • 使用 TableView 并要求您自定义 TableViewRow
    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    相关资源
    最近更新 更多