【问题标题】:React-Native ImageBackground repeat not workingReact-Native ImageBackground 重复不起作用
【发布时间】:2019-11-07 15:39:54
【问题描述】:

我开始学习 react-native,遇到了一个问题。 我需要一张图片在背景中重复,但它被拉伸了。 似乎 resizeMode 不起作用。

import React, { Component } from 'react';
import { Image, ImageBackground, StyleSheet, Button, View, Text } from 'react-native';

const styles = StyleSheet.create({
  home: {
    flex: 1,
    flexDirection: 'column',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'transparent',
  },
  backgroundImage: {
    flex: 1,
    resizeMode: 'repeat',
    backgroundColor: '#882829'
  }
});

export class HomeScreen extends Component {
  render() {
    return (
      <View style={{flex: 1}}>
        <ImageBackground source={require('../assets/stain_pattern.png')} style={styles.backgroundImage}>
          <View style={styles.home}>
            <Text>Home Screen</Text>
            <Button
              title="Go to Details"
              onPress={() => this.props.navigation.navigate('Details')}
            />
          </View>
        </ImageBackground>
      </View>
    );
  }
}

【问题讨论】:

    标签: react-native repeat imagebackground


    【解决方案1】:

    您需要使用 imageStyle={{resizeMode: 'repeat'}}。参考文档link

    您需要在图像样式中应用重复

    <ImageBackground
      source={require('../assets/stain_pattern.png')}
      style={styles.backgroundImage}
      imageStyle={{ resizeMode: 'repeat' }}
    >
      <View style={styles.home}>
        <Text>Home Screen</Text>
        <Button
          title="Go to Details"
          onPress={() => this.props.navigation.navigate('Details')}
        />
      </View>
    </ImageBackground>;
    

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      • 2018-08-30
      相关资源
      最近更新 更多