如何在React Native中将文本浮动在另一个文本上

KD.*_*KD. 5 react-native react-native-flexbox

在此处输入图片说明

这是一个要实现的示例,下面是组件结构的细分

在此处输入图片说明 这是当前代码的方式:

             <View style={styles.buttonHolder}>
                <Text style={styles.greenButtonIcon}>
                    FB
                </Text>
                <Text style={styles.greenButtonText}>
                    {this.props.buttonName}
                </Text>
            </View>
Run Code Online (Sandbox Code Playgroud)

我的问题在这里,因为文本与整个框居中对齐,所以我无法为文本和图标提供弹性值,因为那样会使它们具有自己的空间并且不会浮动。

你能帮忙吗?如果需要更多信息,请告诉我。

Noi*_*art 3

尝试将它们放在buttonHolder. 设置buttonHolderjustifyContentalignItems居中。然后将绿色按钮设置alignSelfflex-start

<View style={styles.buttonHolder}>
    <View style={styles.absolute}>
        <Text style={styles.greenButtonIcon}>
            FB
        </Text>
    </View>
    <View style={styles.absolute}>
        <Text style={styles.greenButtonText}>
            {this.props.buttonName}
        </Text>
    </View>
</View>

const styles = StyleSheet.create({
    absolute: {
        position: 'absolute',
        height: '100%',
        width: '100%',
        alignContent: 'center',
        justifyContent: 'center'
    },
    styles.greenButtonIcon: {
        alignSelf: 'flex-start'
    }
})
Run Code Online (Sandbox Code Playgroud)