reactjs - React Native 中的响应式图像

标签 reactjs react-native native-base

我从 Facebook API 获取一些图像,我想将它们显示为响应式,宽度为 100%,高度为自动。问题似乎是 React Native 裁剪了我的图像。

我尝试了这些解决方案:

Solution 1

Solution 2

此外,我尝试使用react-native-auto-height-image并将其宽度设置为屏幕的宽度。

实际代码:

<TouchableOpacity onPress={() => Linking.openURL(post.url)}>
      <Card style={{ flex: 1 }}>
        <CardItem>
          <Left>
            <Thumbnail source={ThumbnailImage} />
            <Body>
              <Text>My text</Text>
              <Text note>{createdTime}</Text>
            </Body>
          </Left>
        </CardItem>
        <CardItem>
          <Body>
            <AutoHeightImage
              width={Dimensions.get('window').width - 35}
              source={{ uri: post.media.image.src }}
            />
            <Text style={{ marginTop: 10 }}>{post.description}</Text>
          </Body>
        </CardItem>
      </Card>
    </TouchableOpacity>

PS:应用程序正在使用 Native Base 作为 UI 库。

最佳答案

这个问题可以通过使用paddingTop、width、position轻松解决。只需尝试下面的代码即可。

<View style={{width:'100%',paddingTop:'100%'}}>
  <Image source={{uri:url}} style={{position:'absolute',left:0,bottom:0,right:0,top:0,resizeMode:'contain'}} />
 </View>

在上面的代码中,根据所需的图像框大小更改 width 和 paddingTop。

关于reactjs - React Native 中的响应式图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52675852/

相关文章:

reactjs - ScrollView 无法在 React Native 应用程序中启用滚动

react-native - 我如何在 React Native 中使用 connectStyle 和 connect?

react-native - 如何在全屏模式下使用 KeyboardAvoidingView?

react-native - React Android 中的 native 自动链接问题(RN 0.61.5)

android - 在 google chrome 浏览器中 React Native Android 深度链接

javascript - 如何通过 HTTP 请求从图像 Uri 发送图像? (React Native 和 Django 后端)

javascript - undefined is not a function (evaluating '_this2.closeDrawer()') react native app 错误

javascript - 为什么我的函数不返回组件? react

javascript - 编写多个 React 组件的更有效方法?

javascript - 如何将Base64 url​​转换为图像对象