Scrollview中的React-native Listview不在android中滚动
在我们的React-native项目中,我们有一个屏幕,它有一个父Scrollview(带有pull to refresh),在scrollview中我们有Listview(作为chilld视图).
在iOS中,我们可以滚动Scrollview(父级)以及Listview(子视图). 但在android中,我们无法滚动Child Listview.当我们尝试滚动子Listview时,父视图将滚动.儿童视图没有获得触摸. 这与React-native问题有关吗?谁能告诉我如何解决这个问题? 代码段: <ScrollView contentContainerStyle={styles.contentContainerStyle} refreshControl={this.getRefreshControl()}> <View> Some header </View> <MyComponent> </MyComponent> <ListView /* This list view is not scrolling in Android */ dataSource={dataSource} initialListSize={10} renderRow={this.renderRow} renderSeparator={this.renderSeparator}/> </ScrollView> 解决方法
您不应该将ListView放在ScrollView中,因为ListView类实现了自己的滚动,它只是不接收手势,因为它们都由父ScrollView处理.我强烈建议你以某种方式简化你的布局.例如,您可以将要滚动的视图添加到ListView作为页眉或页脚.
更新: 从API Level 21(Lollipop)开始,Android SDK正式支持嵌套滚动容器. View和ViewGroup类中有许多方法可以提供此功能.要在Lollipop上进行嵌套滚动工作,您必须通过将android:nestedScrollingEnabled =“true”添加到其XML声明或通过显式调用setNestedScrollingEnabled(true)来为子滚动视图启用它. 如果要在Lollipop之前的设备上进行嵌套滚动工作(您可能需要这样做),则必须使用支持库中的相应实用程序类.首先,您必须使用NestedScrollView替换ScrollView.后者实现NestedScrollingParent和NestedScrollingChild,因此它可以用作父卷轴或子滚动容器. 但是ListView不支持嵌套滚动,因此您需要对其进行子类化并实现NestedScrollingChild.幸运的是,Support库提供了NestedScrollingChildHelper类,因此您只需创建此类的实例并从视图类的相应方法调用其方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |