【问题标题】:why input field not display full width in android?为什么输入字段在android中不显示全宽?
【发布时间】:2017-01-15 01:46:23
【问题描述】:

我正在使用react-native。我的输入字段没有显示在完整的width 上,为什么?但是当我检查 IOS 时,它可以正常工作,以全宽显示输入字段。 这是我的代码 https://rnplay.org/apps/aHRkHA

import React from 'react';
import {
  registerComponent,
} from 'react-native-playground';
import {
  StatusBar,
  StyleSheet,
  Text,
  TextInput,
  View,
} from 'react-native';

class App extends React.Component {
  render() {
    return (
           <View style={styles.container}>

                <Text style={styles.heading}> Login</Text>
                <TextInput
                    style={styles.loginInput}
                    placeholder="Type here to translate!"
                />
            </View>
    );
  }
}

const styles = StyleSheet.create({
    container: {
        backgroundColor: '#EF501E',
        flex: 1,
        alignItems: 'center'
    },
    logo: {
        width: 50,
        height: 50
    },
    heading: {
        fontSize: 30,
        marginTop: 20
    },
    loginInput: {
        height: 50,
        borderWidth: 1,
        borderColor: '#33090C',
        flexDirection: 'row',
        justifyContent: 'center',
    }
});

registerComponent(App);

【问题讨论】:

    标签: android reactjs react-native react-router


    【解决方案1】:

    尝试用alignSelf: 'stretch' 覆盖父级的alignItems: 'center' 以获得&lt;TextInput&gt;

    <View style={styles.container}>
      ...
    
      <View style={{alignSelf: 'stretch'}}>
        <TextInput
          style={styles.loginInput}
          placeholder="Type here to translate!"
        />
      </View>
    </View>
    

    【讨论】:

    • 对不起,我不使用 RN Playground。你能更新自己吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多