视图内的 ReactNative ScrollView
ReactNative ScrollView inside a View
我正在尝试在 ReactNative 的视图中制作滚动视图。出于某种原因,我无法在 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
进行测试
谢谢,
马格努斯
您应该给 ScrollView 一个高度。来自 docs;
中的示例
<ScrollView style={styles.scrollView}>
...
...
var styles = StyleSheet.create({
scrollView: {
height: 300,
},
});
不要忘记像这样从 React Native 导入 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,
}
});
我正在尝试在 ReactNative 的视图中制作滚动视图。出于某种原因,我无法在 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
进行测试谢谢, 马格努斯
您应该给 ScrollView 一个高度。来自 docs;
中的示例<ScrollView style={styles.scrollView}>
...
...
var styles = StyleSheet.create({
scrollView: {
height: 300,
},
});
不要忘记像这样从 React Native 导入 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,
}
});