javascript - 如何在 React Native 中将两个按钮放在同一行中?

标签 javascript reactjs react-native jsx

在弹出对话框中,我想将按钮放在同一行,但现在我变成了这样 /image/sJ30p.png.Following是给定的样式。

    <PopupDialog
                    ref={popupDialog => {
                      this.popupDialog = popupDialog;
                    }}
                    dialogStyle={{ backgroundColor: "#ddd", height: 200, width:320, border:10,padding:10}}
                    overlayBackgroundColor="#fff"
                    dismissOnTouchOutside={true}
                         >
                 <View style={styles.dialogContentView}>
                 <Text style={{fontSize:18}}>Are you sure you want to submit?</Text>
                 <View style={styles.button_1}>
                 <Button
    title="Yes"
    onPress={() => {
    console.log('clicked')
    }}
    />
    </View>
    <View style={styles.button_1}>
    <Button
    title="No"
    onPress={() => {
    console.log('clicked')
    }}
    />
    </View>
                </View>
                  </PopupDialog>

.....
....

dialogContentView: {
  flex: 1,
    flexDirection: 'column',
    justifyContent: 'space-between'
},
button_1:{

      width: '40%',
      height: 30,

最佳答案

添加View两者的 parent Button具有样式的组件 flexDirection: 'row'</Text> 之后

<View style={{ flexDirection: 'row' }}>
  <View style={styles.button_1}>
    <Button
      title="Yes"
      onPress={() => {
        console.log('clicked');
      }}
   />
   </View>
   <View style={styles.button_1}>
     <Button
       title="No"
       onPress={() => {
         console.log('clicked');
       }}
     />
   </View>
 </View>

你可以试试这个snack

关于javascript - 如何在 React Native 中将两个按钮放在同一行中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52759354/

相关文章:

javascript - react 。仅指定一个 div 的索引

javascript - 将自定义错误消息从 Express JS 发送到 Backbone

javascript - 你能得到(如果可能的话使用 jQuery)元素的当前滚动位置吗?

javascript - 访问本地存储时遇到问题

javascript - CKEditor React 图像调整大小插件

ReactJS - 切换状态的优雅方式

javascript - ReactJS 中按钮和普通文本之间的条件渲染

react-native - SegmentedControlIOS for android in react-native

java - React Native : NoClassDefFoundError - android. support.v4.app.FragmentActivity

javascript - 为什么我不能按名称选择表单元素并使用它们的值使用 jQuery 设置变量