不懂为啥这里设置paddingLeft后,右边出现空白

来源:7-5 ImageBackground-View和Image的结合

佚__名

2023-04-11

图片描述
完整代码:

import React, {useRef} from 'react';
import {StyleSheet, ImageBackground, View, Image} from 'react-native';

import bg_card from '../assets/images/bg_card.png';
import icon_bank from '../assets/images/icon_bank.png';

export default () => {
  // const viewRef = useRef(null);
  // const imgRef = useRef(null);

  return (
    <View style={styles.root}>
      <ImageBackground
        style={styles.viewStyle}
        imageStyle={styles.imgStyle}
        source={bg_card}
        // ref={viewRef}
        // imageRef={imgRef}
      >
        <Image style={styles.icon_logo} source={icon_bank} />
      </ImageBackground>
    </View>
  );
};

const styles = StyleSheet.create({
  root: {
    width: '100%',
    height: '100%',
    flexDirection: 'column',
  },
  viewStyle: {
    width: '100%',
    height: 150,
    flexDirection: 'row',
    alignItems: 'flex-start',
    paddingLeft: 20,
  },
  imgStyle: {
    resizeMode: 'cover',
    borderRadius: 12,
  },
  icon_logo: {
    width: 48,
    height: 48,
  },
});
写回答

1回答

FE大公爵

2023-04-12

这里应该是内部布局计算的bug,你可以把viewStyle样式里的宽度设置成固定值,比如取屏幕宽度。

0
0

RN从0到1系统精讲与小红书APP实战

30+小案例+2个实战项目,快人一步提升个职业竞争力

295 学习 · 211 问题

查看课程