我需要创建两个或更多的按钮,将等于widthhorizontally aligned,根据屏幕宽度按钮宽度可能会有所不同.

这里的示例图像

推荐答案

可以将按钮包装到弯曲视图中:

import React, { Component } from 'react';
import { Button, View, StyleSheet } from 'react-native';

export default const FlexedButtons () => (
  <View style={styles.container}>
     <View style={styles.buttonContainer}>
      <Button title="Button 1"/>
    </View>
    <View style={styles.buttonContainer}>
      <Button title="Button 2"/>
    </View>
  </View>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
  },
  buttonContainer: {
    flex: 1,
  }
});

下面是一个关于草图的工作示例:

React-native相关问答推荐

react-native useEffect / useFocusEffect / useCallback 没有正确更新

React js 做通用头部

如何获取 iOS 版本?

PanResponder 在第二次拖动时将 Animated.View 捕捉回原始位置

IntelliSense 在第一项后无法在 React Native 样式表中工作

React 从 babel 6 到 babel 7 的原生升级

react-native android中出现此问题Cannot convert argument of type class org.json.JSONArray的原因是什么?

在 React Native 中计算两个 lat+lng 坐标之间的距离?

如何在react-native 中加密和解密文本?

如何在 React Native For Android 中删除启动画面后的白屏

如何清除react-native webview cookie?

更改默认的 React Native 下拉箭头图标

在Android上更改高度时react-native TextInput显示错误

如何将捕获的图像与 react-native-camera 一起使用

如何在不使用 JSX 的情况下在 React Native 中制作组件?

React Native 动画 - zoom 时 translateX 和 translateY

React-Native:更改 ImageBackground 的不透明度 colored颜色

使用 React Native 运行 Firebase 3.0 时出错

如何从 react-native-fbsdk 获取用户信息(邮箱、姓名等)?

Flatlist getItemLayout 用例