在<View />中以原生方式对齐彼此

Sto*_*ace 5 css view reactjs react-native

如何将两个项目(图标/文本)对齐?

<TouchableOpacity
        key = {index}
        onPress = {() => this._onPress(key)}
        style = {containerStyle.container}>
        <View>
          <Icon 
            name = {Platform.OS === "ios" ? "ios-checkmark-outline" : "md-checkmark"}
            size = {24}
            style = {{ paddingLeft: 10, color: "#108EE9"}} /> 
          <Text 
            style = {this._createStyleText(key)}>
          {key}
          </Text>
        </View>
  </TouchableOpacity>

const containerStyle = StyleSheet.create({
  container: {
    padding: 8,
    backgroundColor: "#ffffff",
  },
}); 

const textStyle = StyleSheet.create({
  unselectedText: {
      paddingLeft: 45,
      color: "#000000",
      fontWeight: "normal",
  },

}); 
Run Code Online (Sandbox Code Playgroud)

现在,这样对齐:

icon
       text
Run Code Online (Sandbox Code Playgroud)

我需要它们是这样的

icon  text
Run Code Online (Sandbox Code Playgroud)

age*_*unt 6

您可以使用flexDirection布置行中的项目.默认为列

<TouchableOpacity
        key = {index}
        onPress = {() => this._onPress(key)}
        style = {containerStyle.container}>
        <View style={containerStyle.rowContainer}>
          <Icon 
            name = {Platform.OS === "ios" ? "ios-checkmark-outline" : "md-checkmark"}
            size = {24}
            style = {{ paddingLeft: 10, color: "#108EE9"}} /> 
          <Text 
            style = {this._createStyleText(key)}>
          {key}
          </Text>
        </View>
  </TouchableOpacity>

const containerStyle = StyleSheet.create({
  container: {
    padding: 8,
    backgroundColor: "#ffffff",
  },
  rowContainer: {
    flexDirection: 'row'
  }
}); 

const textStyle = StyleSheet.create({
  unselectedText: {
      paddingLeft: 45,
      color: "#000000",
      fontWeight: "normal",
  },

}); 
Run Code Online (Sandbox Code Playgroud)

  • 不响应本机 (2认同)