如何在React Native中根据屏幕大小更改svg大小?

时间:2020-09-10 15:01:16

标签: css reactjs image react-native svg

我在React Native中创建了自适应布局,因此我要做的就是使我的svg图像比例与屏幕尺寸成比例。如何在React Native中使用react-native-svg做到这一点?

1 个答案:

答案 0 :(得分:1)

使用react-native-responsive-screen可以根据屏幕大小使用值,如下所示:



import {widthPercentageToDP as wp, heightPercentageToDP as hp} from 'react-native-responsive-screen';

class Login extends Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.textWrapper}>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: { flex: 1 },
  textWrapper: {
    height: hp('70%'), // 70% of height device screen
    width: wp('80%')   // 80% of width device screen
  }
});

export default Login;