View中的ReactNative ScrollView

时间:2016-08-13 07:02:48

标签: android react-native android-scrollview

我试图在ReactNative中的View中创建一个scrollview。出于某种原因,我无法在ScrollView中滚动。

render() {
    return (
      <View>
        <View>
          <Text>Top</Text>
        </View>
        <ScrollView >
          <Text>Line 1</Text>
          <Text>Line 2</Text>
          <Text>Line 3</Text>
          <Text>Line 4</Text>
          <Text>Line 5</Text>
          <Text>Line 6</Text>
          <Text>Line 7</Text>
          ...
        </ScrollView>
      </View>
    );
  }

这里有什么问题?我在Android上测试

谢谢, 马格努斯

2 个答案:

答案 0 :(得分:3)

您应该为ScrollView指定一个高度。来自docs;

中的示例
<ScrollView style={styles.scrollView}>
...
...
var styles = StyleSheet.create({
  scrollView: {
    height: 300,
  },
});

答案 1 :(得分:1)

不要忘记从反应本机导入scrollview,如下所示:import {   文本,   视图,   滚动型 来自'react-native';

    render() {
        return (
          <View style={styles.container}> // style in firstview
            <View>
              <Text>Top</Text>
            </View>
            <ScrollView contentContainerStyle={styles.Scroll}>// and give style in scrollview
              <Text>Line 1</Text>
              <Text>Line 2</Text>
              <Text>Line 3</Text>
              <Text>Line 4</Text>
              <Text>Line 5</Text>
              <Text>Line 6</Text>
              <Text>Line 7</Text>
            </ScrollView>
          </View>
        );
      }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'orange',
        justifyContent: 'center',
        // alignItems: 'center'
    },
    Scroll: {
      height: 1000,
      paddingVertical: 30,
  }
});

相关问题