React native React Native如何使用键盘AvoidingView
当我开始键入一些消息时,标题和聊天容器都会向上移动 我曾尝试在我的视图容器中使用KeyboardAvoidingView,但是,它不起作用,我不确定KeyboardAvoidingView是否是控制视图中键盘的最佳解决方案,并且不熟悉它 下面是我的代码:React native React Native如何使用键盘AvoidingView,react-native,keyboard,React Native,Keyboard,当我开始键入一些消息时,标题和聊天容器都会向上移动 我曾尝试在我的视图容器中使用KeyboardAvoidingView,但是,它不起作用,我不确定KeyboardAvoidingView是否是控制视图中键盘的最佳解决方案,并且不熟悉它 下面是我的代码: render() { const { myName, user, nome, message } = this.props; return ( <View style={STYLES.main}> <Animat
render() {
const { myName, user, nome, message } = this.props;
return (
<View style={STYLES.main}>
<Animatable.View
style={STYLES.container}
animation={FADEIN}
easing='ease-in'
duration={1000}
>
<RenderHeader3 press={() => Actions.detalhes()} hcolor={'#298CFF'} color={'#FFF'} text={nome} icon={null} isize={null} />
<ScrollView contentContainerStyle={{ paddingHorizontal: 10, paddingTop: 5 }}>
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={null}
keyboardVerticalOffset={60}
>
<ListView
enableEmptySections
dataSource={this.dataSource}
renderRow={this.renderRow}
/>
</KeyboardAvoidingView>
</ScrollView>
<View style={{ flexDirection: 'row', backgroundColor: '#1A1C27', padding: 10 }}>
<View style={{ flex: 4 }}>
<TextInput
style={[STYLES.titleTxt, { color: '#000', backgroundColor: '#FFF', borderRadius: 40, paddingLeft: 13, paddingRight: 10 }]}
multiline
value={message}
onChangeText={(texto) => this.props.modificaMensagem(texto)}
/>
</View>
<View style={{ justifyContent: 'center', alignItems: 'center', paddingLeft: 10 }}>
<TouchableOpacity
style={{
height: 40,
width: 40,
borderRadius: 40,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#298CFF',
paddingRight: 2
}}
activeOpacity={0.5}
onPress={() => this.props.createChat(myName, user, nome, message)}
>
<CustomIcon
name='paper-plane'
size={25}
color='#FFF'
/>
</TouchableOpacity>
</View>
</View>
</Animatable.View>
</View>
);
}
}
进行此更改
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior="height"
keyboardVerticalOffset={60}
>
KeyboardAvoidgView有3种行为类型:枚举“高度”、“位置”和“填充”,但在代码中将其设置为null。 其次,您还没有添加键盘AVOIDGVIEW和TextInput组件
KeyboardAvoidgView有3种行为类型枚举“高度”、“位置”、“填充”,但您将其设置为nullHi,发现了相同的问题。我用键盘awarscrollview为iOS做了分类,但对于Android,我用的是键盘avoidingview,无法在键盘和文本输入之间定义一个边距。您是否找到了解决方案或解决方法?谢谢hi@VinilPrabhu,不起作用,不确定我做错了什么,我附加了一个新图像,通过将行为设置为“高度”@GustavoMenezes KeyboardAvoidingView应该是根标记,所有其他元素都应该包含在其中,如scrollview、textbox等。根据您的示例,您的代码应该与我所做的差不多。但是仍然无法工作,您认为我必须在android清单文件中更改某些内容吗?android:windowSoftInputMode=adjustResize将这一行添加到您的清单文件中
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={'height'}
keyboardVerticalOffset={60}
>