React本机动画(动画)不适用于Android
当屏幕上的键盘被调用时,我正在尝试设置图像的动画以缩小图像(请参见下面的代码)。在IOS上运行,但在Android上不运行:( 我在网上搜索过解决方案,但到目前为止没有任何效果。有什么建议吗 提前谢谢React本机动画(动画)不适用于Android,android,react-native,animation,Android,React Native,Animation,当屏幕上的键盘被调用时,我正在尝试设置图像的动画以缩小图像(请参见下面的代码)。在IOS上运行,但在Android上不运行:( 我在网上搜索过解决方案,但到目前为止没有任何效果。有什么建议吗 提前谢谢 constructor(props) { super(props); this.imageSize = new Animated.Value(imageSizeNormal); } componentWillMount() { this.keyboardWillShowSub
constructor(props) {
super(props);
this.imageSize = new Animated.Value(imageSizeNormal);
}
componentWillMount() {
this.keyboardWillShowSub = Keyboard.addListener('keyboardWillShow', this.keyboardWillShow);
this.keyboardWillHideSub = Keyboard.addListener('keyboardWillHide', this.keyboardWillHide);
}
componentWillUnmount() {
this.keyboardWillShowSub.remove();
this.keyboardWillHideSub.remove();
}
keyboardWillShow = (event) => {
Animated.timing(this.imageSize, {
toValue: imageSizeSmall
}).start();
};
keyboardWillHide = (event) => {
Animated.timing(this.imageSize, {
toValue: imageSize
}).start();
};
render() {
return (
<Animated.Image
source={require('../../assets/circle.png')}
resizeMode="contain"
style={[styles.logo, { height: this.imageSize, width: this.imageSize}]}
/>
)
}
const imageSizeNormal = Dimensions.get("window").width/2;
const imageSizeSmall = Dimensions.get("window").width/4;
构造函数(道具){
超级(道具);
this.imageSize=新的动画.Value(imageSizeNormal);
}
组件willmount(){
this.keyboardWillShowSub=Keyboard.addListener('keyboardWillShow',this.keyboardWillShow);
this.keyboardWillHideSub=Keyboard.addListener('keyboardWillHide',this.keyboardWillHide);
}
组件将卸载(){
此.keyboard将显示sub.remove();
此.keyboard将隐藏sub.remove();
}
键盘将显示=(事件)=>{
动画。计时(此。图像大小{
toValue:ImageSizesMail
}).start();
};
键盘willhide=(事件)=>{
动画。计时(此。图像大小{
toValue:imageSize
}).start();
};
render(){
返回(
)
}
常量imageSizeNormal=尺寸.get(“窗口”).width/2;
const imageSizeSmall=Dimensions.get(“窗口”).width/4;
我是这样解决的
我做的第一件事是将关键字“keyboardWill…”改为“keyboardDid…”
其次,我在AndroidManifest.xml中添加了以下内容
android:fitsSystemWindows="true"
android:windowSoftInputMode="adjustResize"
资料来源:
最终找到了一个有效的解决方案。从技术上讲,它是多种解决方案的组合。