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

<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",
  },

}); 

现在,这些数据是这样排列的:

icon
       text

我需要他们像这样

icon  text

推荐答案

您可以使用flexDirection在行中布局项目.默认值为column

<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",
  },

}); 

React-native相关问答推荐

无法读取 @react-native-async-storage/async-storage 的未定义属性setItem

应用管理

如何在 Recompose 中使用 withHandlers 将 refs 添加到功能组件并在 ScrollView 上调用 ScrollTo?

如何解决Readonly<{}> 类型上不存在属性 navigation&

如何在 React Native 的嵌套 Touchable 中传播touch 事件?

React-Native 是单线程执行还是多线程执行?

如何在 Crashlytics (Fabrics) 中有效地对非致命异常进行分组?

React Native this.'function' 不是函数

使用带有 react-native 的 WebView 设置用户代理

如何将组件中的props传递给 FlatList renderItem

路由状态没有通过 redux 保持在 react-native

React Native STUCK 启动打包器

try 在 Android 上运行我的 React Native 应用程序时出错

React Native 无法运行堆栈跟踪

使用来自另一个页面的 fetch 调用函数返回结果值

如何将时刻日期转换为字符串并删除时刻对象

如何从 React-Native 中的另一个类调用函数?

如何在 react-native 中重叠

Gradlew bundleRelease 不会在 react-native 中生成发布 apk

将现有的 React Native 项目转换为 Expo