在 React Native 中向图像添加填充?

Add padding to images in React Native?

我正在尝试为我正在处理的 React 本机应用程序中的某些图像添加填充。图像根据设备宽度调整大小,以便每行显示四个。在 this.props.images 中有 9 张图像没有任何填充显示。

我试过将图像包装在一个填充为 1 的视图中,如下所示:

renderRow(rowData){
 const {uri} = rowData;
return(
<View style={{padding: 1}}>
  <Image style={styles.imageSize} source={{uri: uri}} />
</View>
)
}

但是当我尝试时,只有前三张图片带有填充。其余图像不会出现。

我的全部代码在这里:

class ImageList extends Component {
componentWillMount(){
const ds = new ListView.DataSource({
  rowHasChanged: (r1, r2) => r1 !== r2
});
this.dataSource = ds.cloneWithRows(this.props.images);
}

renderRow(rowData){
 const {uri} = rowData;

 return(
  <Image style={styles.imageSize} source={{uri: uri}} />
 )
}

  render() {
    return (
      <View>
        <ListView
          contentContainerStyle={styles.list}
          dataSource={this.dataSource}
          renderRow={this.renderRow}
        />
      </View>
    );
  }
}

var styles = StyleSheet.create({
  imageSize: {

//newWidth is the width of the device divided by 4. 
//This is so that four images will display in each row. 
    width: newWidth,
    height: newWidth,
    padding: 2
  },
  list: {
        flexDirection: 'row',
        flexWrap: 'wrap'
    }
});

如何添加填充并使我的所有图像正确显示?

这是我希望我的应用程序如何显示图像的图像。

但这是当我将来自 renderRow 函数的 return 包装在带填充中时的显示方式。有填充,这是我想要的,但只显示前 3 张图片。我想要显示所有 9 张带填充的图片。

我能够通过使用 Thomas 在评论部分提供的建议来解决我的问题。

我所做的是添加 alignSelf:'flex-start'

代码如下所示:

renderRow(rowData){
 const {uri} = rowData;
return(
<View style={{padding: 1, alignSelf: 'flex-start'}}>
  <Image style={styles.imageSize} source={{uri: uri}} />
</View>
)
}

图片现在可以正确显示了。