首页 > 解决方案 > 如何使用 react-native 和 align 让 flex 元素缩小到它们的内容?

问题描述

我有:

        <StyledSurface style={{ flex: 1, flexDirection: 'row', flexWrap: 'wrap' }}>
            {conversations.map((c, i) => (
                <Surface style={{ backgroundColor: 'red', width: '46%', margin: '2%', flexDirection: 'column', flexShrink: 1, alignSelf: 'flex-start'}} key={i}>
                    <Text style={{flex: 1}}>{c.title}</Text>
                </Surface>
            ))}
        </StyledSurface>

这最终看起来像:

在此处输入图像描述

但是我希望每个红色框都缩小(垂直)以适应内容并具有相等的间距?

我错过了什么?

标签: cssreact-nativeflexboxreact-flexbox-grid

解决方案


在 View 容器上添加:

alignSelf: 'flex-start',

应该做的伎俩


推荐阅读