无法以编程方式设置网格布局高度

Unable to set GridLayout height programatically

我正在尝试为每个元素在 ListView 上执行滑动操作。整个视图是 AbsoluteLayout,有两个 GridLayout:一个用作 "foreground"(列表元素),另一个用作 "background"(滑动操作)。我希望它们都具有相同的 "foreground" 高度(这是动态的并且每个列表元素都不同)。

我在 Android 上成功实现了这个 - 我在 layoutChanged 事件上调用了一个方法

onLayoutChanged(args: EventData) {
    const foregroundNotificationTemplate = (<AbsoluteLayout>(args.object)).getChildAt(1);
    const backgroundButtons = (<AbsoluteLayout>args.object).getChildAt(0);
    backgroundButtons.height = foregroundNotificationTemplate.getActualSize().height;
}

不幸的是,这不适用于 iOS。我尝试访问 Frame 和 UiView,但没有成功 - 它具有背景内容的高度。

在 Nativescript Playground 上展示问题的演示: https://play.nativescript.org/?template=play-ng&id=4LRwDC

您不一定非要使用 AbsoluteLayout,因为您正在使用任何布局都可能的翻译动画位置。所以使用 GridLayout 而不是 AbsoluteLayout 应该可以解决你在两个平台上的问题,你也可以摆脱 layoutChanged 测量高度的事件。

另请注意,您的 ListView 项模板不能是动态的,您不应使用 ngIf 或任何会改变列表项结构的内容,而应使用多个模板。

对于任何正在寻找工作解决方案的人,这就是 Manoj 提出的建议:https://play.nativescript.org/?template=play-ng&id=yXggcv