菜鸟学习RN之路---控件排版

一行展示2个控件,一个居右,一个居中,类似下图这种


image.png

现在最外面设置一个横向布局,中间的控件居中用justifyContent和alignItems展示,右边的控件居右,使用绝对布局,right: 4,距离右边边缘4个单元

代码如下:

<View
                        style={{
                            backgroundColor: "#fff",
                            height: 40,
                            flexDirection: "row",
                            // justifyContent: "space-around",
                        }}
                    >
                        <View
                            style={[
                                {
                                    justifyContent: "center",                                  
                                    alignItems: "center",
                                    flex:1
                                },
                            ]}
                        >
                            <Text
                                style={{
                                    fontWeight: "bold",
                                    fontSize: 13,
                                    textAlign: "center",
                                }}
                                numberOfLines={2}
                            >
                                {'测试'}
                            </Text>
                        </View>
       
                        
                        <View style={{
                           justifyContent: "center",
                            alignItems:'center',
                            right: 4,
                            position: 'absolute',
                        }}>
                                <Image
                                    source={imageDown}
                                    style={{ height: 20, width: 20,marginLeft:20 }}
                                ></Image>
                            </View>
                    </View>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容