android - 将图像调整为 View - native react

标签 android css reactjs react-native resize

我想知道是否可以调整图像的大小以使其适合 View 。

这是我现在拥有的

 <View style={styles.container}>
    <View style={styles.header}>
      <Image
        source={headerImage}    
      />

    </View>
    <Text style={styles.basicText}>text</Text>
  </View>

 const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: "#fff"
      },
      header: {
        height: 200, 
        backgroundColor: 'red'
      },
      background: {
        width: null,
        height: null
      },
      image: {

      }

我想让图像适合标题 View 。

最佳答案

添加到 Moti Azu 的答案中,您还需要设置 resizeMode。

image: {
  flex:1,
  height: null,
  resizeMode: 'contain',
  width: null,
}

如果它似乎不起作用,请确保您的 View 样式 container 具有宽度。

关于android - 将图像调整为 View - native react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44883098/

相关文章:

android - Emulator-5554 断开连接!正在取消 'activity launch'!尝试使用 cmd 命令解决但仍然无法正常工作

Android EditText 禁用编辑但允许滚动

javascript - 在 HTML Canvas 上绘制多条路径

html - 文字在图像下方流动

javascript - 如何使用 Jquery 从动态创建的文本框中检索值

reactjs - props.history.push ('/' ) 没有转到页面顶部(需要功能组件)

Android EditText 下一个重点

android - 如何使用 PreferenceFragmentCompat 在首选项之间显示分隔符

reactjs - 为什么我在 "Cannot find file ' 中收到此错误 : './src' ./App'。":?

javascript - 使用 react.js 单击按钮后更新文本