请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

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

图片描述
完整代码:

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,
  },
});

正在回答 回答被采纳积分+3

1回答

FE大公爵 2023-04-12 11:14:48

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

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号