android - 启用双向 ScrollView react 原生

标签 android ios reactjs react-native scrollview

如何在水平和垂直方向启用 ScrollView。但我不想使用 ListView。请建议我该怎么做。我想在两个方向上滚动整个渲染方法 View 。 这是我的代码。在此,所有的TextViewTextInput 都出现在ScrollView 设置之后的一行中。我想要单独查看每个 View 。

render() {
    const { navigate } = this.props.navigation;
    if (this.state.isLoading) {
      return (
        <View style={{ flex: 1, paddingTop: 20 }}>
          <ActivityIndicator />
        </View>
      );
    }
    return (
<View style={styles.MainContainerViewCamp}>

<Text style={{ padding: 5, fontSize: 35, backgroundColor: '#00BCD4', marginBottom: 7 }}>Data Slabs</Text>
    <ScrollView keyboardShouldPersistTaps='always' style={styles.container}
            directionalLockEnabled={false}
            horizontal={true}>

      <View style={styles.SwitchOuterSectionStyle}>
      <Text style={styles.textViewContainer}>A(1,1) </Text>
        <TextInput placeholder="CPR*" value={this.state.cpr1} style={styles.TextInputStyleClass}

           keyboardType='numeric'

          onChangeText={cpr1 => this.setState({ cpr1 })} underlineColorAndroid='transparent' />

        <TextInput placeholder="CPM*" value={this.state.cpm1} style={styles.TextInputStyleClass}

           keyboardType='numeric'

          onChangeText={cpm1 => this.setState({ cpm1 })} underlineColorAndroid='transparent' />
      </View>


      <View style={styles.SwitchOuterSectionStyle}>
      <Text style={styles.textViewContainer}>B(0.75,0.75) </Text>

        <TextInput placeholder="CPR*" value={this.state.cpr2} style={styles.TextInputStyleClass}

           keyboardType='numeric'

          onChangeText={cpr2 => this.setState({ cpr2 })} underlineColorAndroid='transparent' />

        <TextInput placeholder="CPM*" value={this.state.cpm2} style={styles.TextInputStyleClass}

           keyboardType='numeric'

          onChangeText={cpm2 => this.setState({ cpm2 })} underlineColorAndroid='transparent' />

      </View>

      <View style={styles.SwitchOuterSectionStyle}>
      <Text style={styles.textViewContainer}>C-Default(0.5,0.5) </Text>
        <TextInput placeholder="CPR*" value={this.state.cpr3} style={styles.TextInputStyleClass}

           keyboardType='numeric'

          onChangeText={cpr3 => this.setState({ cpr3 })} underlineColorAndroid='transparent' />

        <TextInput placeholder="CPM*" value={this.state.cpm3} style={styles.TextInputStyleClass}

          editable={this.state.bud} keyboardType='numeric'

          onChangeText={cpm3 => this.setState({ cpm3 })} underlineColorAndroid='transparent' />

      </View>

      <View style={styles.SwitchOuterSectionStyle}>
      <Text style={styles.textViewContainer}>D(0.25,0.25)</Text>
        <TextInput placeholder="CPR*" value={this.state.cpr4} style={styles.TextInputStyleClass}

           keyboardType='numeric'

          onChangeText={cpr4 => this.setState({ cpr4 })} underlineColorAndroid='transparent' />
        <TextInput placeholder="CPM*" value={this.state.cpm4} style={styles.TextInputStyleClass}

          editable={this.state.bud} keyboardType='numeric'

          onChangeText={cpm4 => this.setState({ cpm4 })} underlineColorAndroid='transparent' />

      </View>

      <View style={styles.SwitchOuterSectionStyle}>
       <Text style={styles.textViewContainer}>E(0,0)</Text>
        <TextInput placeholder="CPR*" value={this.state.cpr5} style={styles.TextInputStyleClass}

          keyboardType='numeric'

          onChangeText={cpr5 => this.setState({ cpr5 })} underlineColorAndroid='transparent' />
        <TextInput placeholder="CPM*" value={this.state.cpm5} style={styles.TextInputStyleClass}

          editable={this.state.bud} keyboardType='numeric'

          onChangeText={cpm5 => this.setState({ cpm5 })} underlineColorAndroid='transparent' />
      </View>

      <TouchableOpacity
        style={styles.SubmitButtonStyle}
        activeOpacity={.5}
        onPress={this.onSaveDataSlabs} >
        <Text style={styles.TextStyle}> SAVE </Text>
      </TouchableOpacity>
    </ScrollView>
  </View>
);
}

这是样式表:-

const styles = StyleSheet.create({

  MainContainerViewCamp: {
    justifyContent: 'center',
    paddingTop: (Platform.OS === 'ios') ? 20 : 30,
    padding: 5,
  },
  SwitchOuterSectionStyle: {
    flexDirection: 'row',
    padding: 4,
    justifyContent: 'center',
    alignItems: 'center'

  },
  textViewContainer: {
    padding: 7,
    fontSize: 17,
    width: 150,
  },
  TextInputStyleClass: {
    textAlign: 'left',
    paddingLeft: 7,
    margin: 10,
    width: 150,
    height: 40,
    borderWidth: 1,
    borderColor: '#00BCD4',
  },
  listViewStyle: {
    borderWidth: 1,
    height: 360,
    borderColor: '#87ceeb',
  },
  SubmitButtonStyle: {
    marginTop: 10,
    paddingTop: 15,
    paddingBottom: 15,
    backgroundColor: '#00BCD4',
    borderRadius: 10,
    borderWidth: 1,
    borderColor: '#fff'
  },
  TextStyle: {
    color: '#fff',
    textAlign: 'center',
  }
});

最佳答案

只需同时设置directionalLockEnabledhorizo​​ntal 使其工作

<ScrollView 
    style={styles.container}
    directionalLockEnabled={false}
    horizontal={true}
>

还有一个 library你可以使用。它是用于 react-native 的四向滚动 Scroller View。

关于android - 启用双向 ScrollView react 原生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48076534/

相关文章:

android - 未设置 Kotlin Dagger 模块

android - 如何在 Android 中使用 GeoTools 显示 map ?

java - 计算缺失数字的数量

java - 如何为自定义 Toast 消息设置自定义持续时间?

javascript - react 属性

ios - 自定义键盘 : get selected text

ios - 如何将 Token Key 和 Token Secret 传递给 Alamofire 请求?

ios - 在 iOS 中使用模板缓冲区

javascript - react 测试库验证DOM嵌套错误

javascript - 更改 Material UI 选择器上的工作日标签