【问题标题】:ScrollView doesn't work when wrapped in a layout包裹在布局中时,ScrollView 不起作用
【发布时间】:2018-11-30 13:10:44
【问题描述】:

我注意到,当 ScrollView 被包裹在另一个布局小部件中时,它会停止响应平移。我正在寻找一种解决方案,以使 ScrollView 即使在包装时也能按预期工作。这是sample app in Playground,我在这里发布它的模板

此示例不滚动:

<AbsoluteLayout #wrapTop class="wrapTop" left="0" top="0" width="100%" height="100%">
<ScrollView orientation="horizontal" sdkExampleTitle sdkToggleNavButton>
    <GridLayout class="m-15" columns="auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto auto">
         <Label width="50" height="50" class="h3 m-15" col="0" text="Title 1"></Label>
         <Label width="50" height="50" class="h3 m-15" col="1" text="Title 2"></Label>
         <Label width="50" height="50" class="h3 m-15" col="2" text="Title 3"></Label>
         <Label width="50" height="50" class="h3 m-15" col="3" text="Title 4"></Label>
         <Label width="50" height="50" class="h3 m-15" col="4" text="Title 5"></Label>
         <Label width="50" height="50" class="h3 m-15" col="5" text="Title 6"></Label>
         <Label width="50" height="50" class="h3 m-15" col="6" text="Title 7"></Label>
         <Label width="50" height="50" class="h3 m-15" col="7" text="Title 8"></Label>
         <Label width="50" height="50" class="h3 m-15" col="8" text="Title 9"></Label>
         <Label width="50" height="50" class="h3 m-15" col="9" text="Title 10"></Label>
         <Label width="50" height="50" class="h3 m-15" col="10" text="Title 10"></Label>
         <Label width="50" height="50" class="h3 m-15" col="11" text="Title 11"></Label>
         <Label width="50" height="50" class="h3 m-15" col="12" text="Title 12"></Label>
         <Label width="50" height="50" class="h3 m-15" col="13" text="Title 13"></Label>
         <Label width="50" height="50" class="h3 m-15" col="14" text="Title 14"></Label>
         <Label width="50" height="50" class="h3 m-15" col="15" text="Title 15"></Label>
    </GridLayout>
</ScrollView>
</AbsoluteLayout>

【问题讨论】:

    标签: nativescript angular2-nativescript


    【解决方案1】:

    我认为您在这里不需要 AbsoluteLayout,至少当您不打算将子组件放置在绝对位置时。

    此外,当您想简单地以水平方向堆叠项目时,您不需要 GridLayout,您可以使用 StackLayout 来代替水平方向。

    我已更新您的 Playground 示例。

    https://www.nslayouts.com/了解更多关于布局的信息

    更新:

    感谢@DrAchernar,他提出了一个有效的观点。如果您打算渲染 n 个看起来相似的项目,您应该考虑使用 ListView / RadListView。 RadListView 支持不同的布局和水平方向,这里应该适合您的要求。

    【讨论】:

    • 感谢您的宝贵时间。我的布局有点复杂——为了举例,我在这里减少了它。我需要将 ScrollView 嵌入到 GridView 中,但就像 AbsoluteLayout 一样,它拒绝响应平移。我更新了 Playground 示例
    • 为什么不在 GridLayout 中使用带有 itemTemplate 的 RadListView?它对您的布局很有用。这样你就不需要scoolview了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 2018-01-21
    • 2020-03-13
    • 2019-09-19
    相关资源
    最近更新 更多