【问题标题】:How to show the most right scroll view item which it's items are dynamic?如何显示最右边的滚动视图项目,它的项目是动态的?
【发布时间】:2017-04-12 21:09:25
【问题描述】:

我正在使用 Nativescript 为从右到左的语言(如波斯语或乌尔都语)创建 android 应用程序。我有水平滚动视图,其中项目使用中继器填​​充。中继器将通过 webservice 获取项目数据,然后将其放入滚动视图中。

<ScrollView id="pishnehadScroll" orientation="horizontal" propertyChange="pchange">
                        <Repeater items="{{ products }} ">
                            <Repeater.itemsLayout>
                                <StackLayout orientation="horizontal"  horizontalAlignment="center">
                                </StackLayout>
                            </Repeater.itemsLayout>
                            <Repeater.itemTemplate>
                                <StackLayout class="pishnehad-items" horizontalAlignment="center">
                                    <Image src="{{ imagesrc }}" />
                                    <Label text="{{ productprice }}" />
                                </StackLayout>
                            </Repeater.itemTemplate>
                        </Repeater>
                    </ScrollView>

由于我需要从右到左显示滚动视图项目,我必须获取 scrollView 的 scrollableWidth 属性并使用 scrollToHorizo​​ntalOffset 函数。 问题是随着 web 服务结果的到来,可滚动宽度不断变化。 如何获得滚动视图的最终可滚动宽度并设置 scrollToHorizo​​ntalOffset 函数以显示滚动视图中的最后一项(最右边的项目)?

【问题讨论】:

标签: android nativescript


【解决方案1】:

除了 pkanev 的评论之外,当您要加载更多项目(通过更了解不适合屏幕的项目)时,我还建议使用 ListView 或 RadListView,而不是 Repeater。原因是因为 RadListView(和 ListView)都在使用虚拟化和单元回收等优化,这大大提高了性能。使用带有大量项目的中继器将在以后导致 OutOfMemory 问题...

除此之外,一旦您的 Web 服务获取了所有数据,您就可以访问名为 scrollableWidth and scrollableHeight 的 ScrollView 属性。由于这很可能是一个异步操作,您可以使用 then 链接到它,并在收到获取的结果后调用可滚动的宽度和高度。你可能需要 例如

var scroll = <ScrollView>page.getViewById("pishnehadScroll");

setTimeout(function() {
    console.log(scroll.scrollableWidth);
}, 300);

使用带有 scrollToIndex 和“缓存”项目索引的 ListView 的另一种方法是使用 here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 2012-11-04
    相关资源
    最近更新 更多