【发布时间】:2021-02-05 01:03:47
【问题描述】:
我正在尝试将动态内容放入固定高度的视图中,在本例中为屏幕高度,而不会溢出(因此不需要垂直滚动)。
这与其他类似问题相反,他们希望 View 的高度由内容决定。
到目前为止我所拥有的:
<SafeAreaView style={styles.container}>
<ScrollView scrollEnabled={false}>
<View style={styles.displayContainer}>
{splitWords.map(word => (
<Text
style={styles.textDisplay}
adjustsFontSizeToFit={true}
numberOfLines={1}
style={{fontSize: 200}}
>
{word}
</Text>
))}
</View>
)}
</ScrollView>
</SafeAreaView>
我尝试了 flex、flexShrink、flexWrap 等的各种组合,但似乎无法理解。 这是样式表:
const styles = StyleSheet.create({
container: {
flex: 1,
},
textDisplay: {
// Not sure what to try here next
},
displayContainer: {
padding: 2,
height: height - 130, // Height is obtained by Dimensions.get('window').height;
width: width, // Width is obtained by Dimensions.get('window').weight;
//alignSelf: 'stretch'
//flex: 0,
//flexWrap: 'nowrap',
//flexDirection: 'column',
//flexShrink: 1,
},
});
我将不胜感激。
【问题讨论】:
-
将 flex:1 添加到您的 ScrollView 样式中。
-
请问,你为什么放 height: height - 130?
标签: javascript react-native flexbox react-native-ios