简体   繁体   中英

Trouble making React Native background full screen

I am using Expo iOS simulator, and have been trying to make the background full screen, but cant make it work.

export default function App() {
  return (
        <ScrollView >
        <View  style={[styles.container]}>
          <Text style={styles.title}>Mt. Fuji</Text>
          <Image source={require('./images/pic.jpeg')} style={styles.uriImg}/>
          <TextImg imageUri={'https://m.media-amazon.com/images/M/MV5BZjRjOTFkOTktZWUzMi00YzMyLThkMmYtMjEwNmQyNzliYTNmXkEyXkFqcGdeQXVyNzQ1ODk3MTQ@._V1_.jpg'} text='Rick & Morty'  style={[styles.text, styles.propImg]} /> 
          <TextImg text='The Butterfly Nebula' imageUri={'https://www.dualdove.com/wp-content/uploads/2020/02/supernova-dying-star-in-the-shape-of-a-butterfly.jpg'} style={[styles.text, styles.propImg]} /> 
        </View> 
      </ScrollView>
  )
};

const styles = StyleSheet.create({
  uriImg: {
    width: 350, 
    height: 200,
    top:110,
  }, 
  propImg: {
    width: 350, 
    height: 200
  }, 
  container:{
    backgroundColor: '#a1c5ff',
    alignItems: 'center',
    flex:1
  });

This is what it looks like right now.

在此处输入图片说明

You can import 'Dimensions' from 'react-native', shown below:

import { Dimensions } from 'react-native';

You can now get the screen width and height from the following:

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;

Once these have been defined you can now set your container width and height to be these values:

container: {
  width: width
  height: height
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM