【问题标题】:Fit content to height of View in React Native (iOS)在 React Native (iOS) 中使内容适合视图的高度
【发布时间】: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


【解决方案1】:

尝试在 ScrollView 组件中添加以下道具。

<ScrollView flex={{ flex: 1 }} contentContainerStyle={{ minHeight: "100%" }}>
   ...
</ScrollView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多