我使用的是原生基本按钮我想把按钮对准屏幕中央我试过这样做:

<Container style={{flex:1,
    flexDirection:'row',
    alignItems:'center',
    justifyContent:'center',}}>
         <Form style={{}}>
              <Item last>
                    <Input placeholder='Username' 
                    style={{color:'white'}}/>
                </Item>
              <Item last>
                  <Input placeholder="Password"
                  style={{color:'white'}} />
              </Item>

              <Button style={{width:170,backgroundColor:'#99004d',marginTop:20,}}>
                    <Text style={{marginLeft:50}}>Login</Text>
              </Button>

              <Text style={{color:'white'}}>{this.props.Name}</Text>
          </Form>
        </Container>

但它减少了输入字段的大小我得到的结果如下:

enter image description here

推荐答案

我没有使用您正在使用的表单/项目组件,但以下是我在设计类似的登录表单时学到的内容:

justifyContent和alignItems样式定义了子项的行为方式,因此请try 将文本输入放到不同于按钮的父项中:

<View style={styles.loginTextSection}>
   <TextInput placeholder='UserName' style={styles.inputText} />
   <TextInput placeholder='Password' style={styles.inputText} secureTextEntry={true}/>
</View>

<View style={styles.loginButtonSection}>
     <Button onPress={() => doLoginStuff()} 
             style={styles.loginButton}
             title="Login"
     />

</View>

const styles = StyleSheet.create({
   loginTextSection: {
      width: '100%',
      height: '30%',
   }

   loginButtonSection: {
      width: '100%',
      height: '30%',
      justifyContent: 'center',
      alignItems: 'center'
   }

   inputText: {
      marginLeft: '20%',
      width: '60%'
   }

   loginButton: {
     backgroundColor: 'blue',
     color: 'white'
   }
}

React-native相关问答推荐

Firebase身份验证Redux使用说明

React-Native:请纠正我对状态如何工作的误解 - 动态文本输入

文本输入提示

什么是 expoClientId?

有人可以帮我实现 Font.loadAsync

ReactNative:在所有组件和操作之间共享 sqlite 实例的最佳方法

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

如何在react-navigation 中将props传递给screens/components

Visual Studio 2017 中的 React Native

ld:找不到-lFirebaseCore clang的库: error: linker command failed with exit code 1 (use -v to see invocation)

React Native:fetch request failed with error - TypeError: Network request failed(…)

React-Native: measure测量一个视图

可以react native使用jQuery

Jest 的配置在更新到 26.x 后抛出type ErrorHandler = (error: mixed, isFatal: boolean) => void

react-native createbottomtabnavigator 隐藏标签栏标签

React Native 中的原生广告

Console.error:no permission handler detected

react-native async 函数返回 promise 但不返回我的 json 数据?

XCode AppIcon 基于方案

无法解析模块react-native-screen