我在React Native中有一个应用程序,我试图在我的应用程序中引入一个图像,但是图像太大了,图像占据了整个屏幕。为了弥补这一点,
imagem:{
flex: 1,
width: null,
height: null,
resizeMode: 'contain'
}
图像本身的大小很好,但是组件太大了,所以很难看到其他组件。
完整的脚本在这里:
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { SafeAreaView, StyleSheet, Text, View, Button, Image } from 'react-native';
export default function App() {
const moedas = [
require('./imagens/m1.png'),
require('./imagens/m5.png'),
require('./imagens/m1.png'),
require('./imagens/m2.png'),
require('./imagens/m3.png'),
require('./imagens/m4.png'),
require('./imagens/m5.png'),
require('./imagens/m6.png'),
require('./imagens/m7.png'),
require('./imagens/m8.png'),
]
let iMoeda = 0
const maxGiros = 20
const [moedaAtual,setMoedaAtual] = useState(moedas[iMoeda])
async function espera(tmp) {
function tempo(ms) {
return new Promise(resolve => setTimeout(resolve,ms))
}
await tempo(tmp)
}
async function girarMoeda() {
}
return (
<SafeAreaView style={estilos.container}>
<View>
<Text>Cara ou Coroa</Text>
<Image style={estilos.imagem} source={moedaAtual}/>
<Button
title='Girar'
onPress={()=>{}}
/>
</View>
</SafeAreaView>
);
}
const estilos = StyleSheet.create({
container:{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
imagem:{
flex: 1,
width: null,
height: null,
resizeMode: 'contain'
}
});
2条答案
按热度按时间wkyowqbh1#
您可以删除Flex:1属性从estilos.imagem
ma8fv8wu2#
将
width
设置为100%,将height
设置为固定大小(为其他组件留出空间),然后包含或覆盖resizeMode
以获得所需的结果。