react-native TextInput 鍵盤(pán)遮擋問(wèn)題

貼一下 我的render里面的代碼 和效果圖

 render() {
        return (
            <Image source={{uri:'bg'}} style={styles.container}>
                 <KeyboardAvoidingView behavior='position' >
                      <View>

                      <View style={styles.logoView}>
                              <Image source={{uri:'grplogo'}} style={styles.grplogo}/>
                      </View>

               

                    <View   style={styles.textInputBoxStyle}>
                          <Image source={{uri:'user'}} style={styles.iconStyle}/>
                          <TextInput
                              style={styles.textInputStyle}
                              maxLength={20}
                              autoCapitalize='none'
                              clearButtonMode="while-editing"
                              placeholder="請(qǐng)輸入用戶名"
                              placeholderTextColor={'rgba(255,255,255,0.8)'}
                              underlineColorAndroid='transparent'
                              onChangeText={(user_id) => this.setState({user_id})}
                              value={this.state.user_id}
                          />
                     </View>

                  <View style={styles.line}/>

                <View   style={styles.textInputBoxStyle2}>
                    <Image source={{uri:'lock'}} style={styles.iconStyle}/>
                    <TextInput
                        autoCapitalize='none'
                        style={styles.textInputStyle}
                        maxLength={20}
                        clearButtonMode="while-editing"
                        placeholder="請(qǐng)輸入密碼"
                        placeholderTextColor={'rgba(255,255,255,0.8)'}
                        secureTextEntry={true}
                        //去掉android默認(rèn)下劃線
                        underlineColorAndroid='transparent'
                        onChangeText={(user_password) =>
                                    this.setState({user_password})}
                        value={this.state.user_password}
                    />
                </View>
                <View style={styles.line}/>


                 <View style={{alignItems:'center'}}>

                <View style={styles.loginBox}>
                    <Text
                        onPress={()=>this._login()}
                        style={styles.loginText}
                    >登錄</Text>
                </View>
                </View>
 
               </View>

            </KeyboardAvoidingView>
            </Image>
           
        );
    }

樣式

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems:'center',
        //justifyContent: 'center',
    },

 
    logoView:{
        paddingTop:150,
        alignItems:'center',
    },
    grplogo:{
        width: 137,
        height:36,
    },

    line:{
        width:width-60,
        height:0.8,
        marginLeft:30,
        marginRight:30,
        backgroundColor:'white'
    },


    textInputBoxStyle:{
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        height:40,
        marginLeft:30,
        marginRight:30,
        marginTop:90,

    },

    textInputBoxStyle2:{
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        height:40,
        marginLeft:30,
        marginRight:30,
        marginTop:40,
    },



    iconStyle:{
        width: 18,
        height: 20,
    },
    textInputStyle: {
      flex: 1,
      paddingLeft:20,
      justifyContent: 'center',
      color:'white'
    },

    loginBox: {
        justifyContent:'center',
        alignItems:'center',
        marginTop: 49,
        backgroundColor: '#4A90E2',
        height: 40,
        width:130,
        borderRadius:20,
    },
    loginText:{
        textAlign:'center',
        fontSize:18,
        color:'white',
        paddingHorizontal:30,
    }
});

效果圖,觀察GRP 距離頂部的距離

C5BD64A1-BB5A-4DDE-AAF2-16E48587B13B.png
F3ACF40D-F917-498A-A65F-C96BCE656CC9.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 最近在項(xiàng)目中,使用TextInput組件的時(shí)候,發(fā)現(xiàn)鍵盤(pán)彈出的時(shí)候,遮蓋了表單。在ReactNative中是否有處...
    以德扶人閱讀 7,605評(píng)論 2 50
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,366評(píng)論 25 708
  • kmokidd ·3 天前 本篇為聯(lián)合翻譯,譯者:寸志,范洪春,kmokidd,姜天意 數(shù)月前,F(xiàn)acebook ...
    東引甌越閱讀 2,042評(píng)論 0 49
  • 第一場(chǎng)雪,輕盈,厚實(shí),時(shí)而捉迷藏星星點(diǎn)點(diǎn),時(shí)而瀑布般一瀉而下,憨厚憨厚地。 爸媽出去串門(mén),中午媽先...
    陳又林閱讀 160評(píng)論 0 1
  • 終于吃飽了,從4點(diǎn)多等到七點(diǎn)多才開(kāi)始出到中山,直到22點(diǎn)多才坐下來(lái)吃東西,突然覺(jué)得出來(lái)一次好不容易啊。 今晚這么晚...
    承思而行閱讀 193評(píng)論 0 0

友情鏈接更多精彩內(nèi)容