【发布时间】:2017-12-21 07:28:56
【问题描述】:
我有一个使用ScrollView 的非常简单的示例,但我似乎无法滚动到底部。
这个例子是完全基本的,我没有做任何特别的事情,但最后一项永远不会完全可见。
import React, { Component } from "react";
import { Text, View, ScrollView, StyleSheet } from "react-native";
import { Constants } from "expo";
const data = Array.from({ length: 20 }).map((_, i) => i + 1);
export default class App extends Component {
render() {
return (
<ScrollView style={styles.container}>
{data.map(d => (
<View style={styles.view}>
<Text style={styles.text}>{d}</Text>
</View>
))}
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
paddingTop: Constants.statusBarHeight
},
text: {
fontWeight: "bold",
color: "#fff",
textAlign: "center",
fontSize: 28
},
view: {
padding: 10,
backgroundColor: "#018bbc"
}
});
这是输出:
【问题讨论】:
-
将
flex: 1添加到容器中应该可以解决问题 -
@AakashSigdel 我有一个类似的用例。
flex: 1没用。我仍在使用各种道具,但到目前为止,每当我滚动到底部时,视图都会反弹,阻止我选择最后一个项目,这恰好是一个按钮。 -
你应该改变正确的答案
标签: javascript reactjs react-native scrollview