React-Native图标未在视图中心对齐

时间:2019-03-29 04:55:26

标签: html react-native

这是我用来在背景颜色为圆形的视图中心放置图标的代码:

import EEIcon from "react-native-vector-icons/Entypo";
              <View
               style={{
                      backgroundColor: "#F2F2F2",
                      alignItems: "center",
                      justifyContent: "center",
                      height: 25,
                      width: 25,
                      borderRadius: 12.5
                    }}
                  >
                    <EEIcon
                      name="location-pin"
                      style={{ color: "#fff", fontSize: 15 }}
                    />
                  </View>

This is how the icon looks like

2 个答案:

答案 0 :(得分:2)

在顶部和左侧的图标上填充空白----

<EEIcon name="location-pin" style={{ color: "#fff", fontSize: 15, paddingTop:3, paddingLeft:2 }} />

这是工作示例 https://snack.expo.io/@msbot01/icon-center

答案 1 :(得分:1)

为了使alignItem和justifyContent工作,应将显示设置为“ flex”:

   style={{
          backgroundColor: "#F2F2F2",
          alignItems: "center",
          justifyContent: "center",
          height: 25,
          width: 25,
          borderRadius: 12.5,
          display:"flex"
    }}