android - TextInput flexDirection :row not working in React-Native

标签 android react-native

我目前正在为一个 Android 项目使用 React-Native。我一直在尝试制作一个 TextInput 字段,该字段旁边有一个图标。但是,出于某些原因,我注意到如果 TextInput 是其子组件之一,则 flexDirection: 'row' 不起作用。我应用样式的整个 View 将自动消失。这是我的代码的一个 fragment :

<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
    <View style={{flexDirection: 'row'}}>
        <Image
            style={{height: 30, width: 30}}
            source={require('./images/email-white.png')}
        />
        <TextInput 
            style={{height: 40}}
            underlineColorAndroid={'transparent'}
            placeholder={'E-mail'}
            placeholderTextColor={'white'}
            onChangeText={(data) => this.setState({ username: data })} />
    </View>
</View>

我还尝试将这两个组件包装在每个单独的 View 中,但问题仍然存在。有没有人知道如何解决这个问题?或者任何人都可以确认这是一个错误?

最佳答案

您的代码稍作修改后对我来说效果很好。我所做的唯一一件事就是为 TextInput 添加宽度,导致图标位于文本输入旁边。

工作代码:

<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
    <View style={{flexDirection: 'row'}}>
        <Image
            style={{height: 30, width: 30}}
            source={require('./images/email-white.png')}
        />
        <TextInput 
            style={{height: 40, width: 300}}
            underlineColorAndroid={'transparent'}
            placeholder={'E-mail'}
            placeholderTextColor={'white'}
            onChangeText={(data) => this.setState({ username: data })} />
    </View>
</View>

关于android - TextInput flexDirection :row not working in React-Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35828486/

相关文章:

android - 如何排除Android Eclipse项目的 "/res"文件夹中的文件

android - groovy.lang.MissingPropertyException : Could not get unknown property 'manifestOutputFile'

ios - React-native包管理器问题

reactjs - react native : `styled-components/native` cannot be resolved by bundler under yarn workspace

android - 关联多个谷歌帐户的 Android Chrome 上的 GAE Python 应用程序(用户服务)错误

android - 在不同的屏幕比例下实现相同的字体大小

android - 以编程方式清除用户自己的应用程序数据

java - 现在该学什么? EJB 或 Android 编程

react-native - react-native中flow和eslint有什么区别?我应该使用哪一个?我可以同时使用吗?

react-native - 如何在 react-native (ANDROID) 中获取预定的本地通知