反应本机滚动子列

React native scroll sub column

我有这样的视图

<View style={styles.columnView}>
  <View style={[styles.columnButtonItem, styles.columnC]}><Text></Text></View>
  <View style={[styles.columnButtonItem, styles.columnA]}><Text></Text></View>
  <View style={[styles.columnButtonItem, styles.columnB]}><Text></Text></View>
  <View style={[styles.columnButtonItem, styles.columnE]}><Text>{value}</Text></View>
  <View style={[styles.columnButtonItem, styles.columnAs]}><Text></Text></View>
  <View style={[styles.columnButtonItem, styles.columnT]}><Text></Text></View>
</View>

经过迭代,我组成了一个table这样的:

有没有办法在单列上添加ScroolView? 例如,我只想在 columnE 上启用滚动。 显然,当我滚动 columnE 时,我想滚动所有 table.

谢谢

绝对定位的视图

如果您知道列的宽度,那么您可以使用与底层 ScrollView 重叠的绝对定位的视图,它们将停止对 ScrollView 的所有触摸。这意味着它只会在绝对定位视图未覆盖的部分上滚动。

所以你可以这样做

render() {
  // set these widths to be the size before row E and the size after row E
  let leftWidth = '33%'; 
  let rightWidth = '33%';
  return (
    <View style={{flex: 1}}>
      <ScrollView style={{flex: 1}}>

        // items for the scroll view go here

      </ScrollView>
      <View style={{position:'absolute', top:0, left: 0, bottom: 0, width: leftWidth}} />
      <View style={{position:'absolute', top:0, right: 0, bottom: 0, width: rightWidth}} />
    </View>
  )
}

小吃

这里有一个展示此实现的小吃。我在绝对定位的视图上设置了一个 backgroundColor ,以便您可以清楚地看到它们。 https://snack.expo.io/@andypandy/partial-scrollview

警告

此解决方案的主要问题是您将无法触摸绝对定位视图下方的任何内容。您可以通过在每个 View 上使用 gestures 捕获触摸,然后将它们映射到 ScrollView 上的位置来缓解这种情况。

我(认为)这就是您要查找的内容...基本上您只能滚动最右侧的列,其余列不可滚动。因此,您必须等待 ScrollView 的本机事件处理程序传播任何更改,然后才能呈现这 4 列的其余部分正在滚动的事实。

https://snack.expo.io/@vincentvella/scroll-example