react-native - React Native滚动视图在android中不起作用
问题描述
我ScrollView
在我的 react-native 应用程序中使用 a 。该应用程序在我的 iOS 模拟器中运行良好,但是当我在我的 Android 模拟器中测试时,ScrollView
它不起作用。
这是我的 React 组件返回的内容
<SafeAreaView style={styles.container}>
<Image
source={require('../assets/images/logo.png')}
style={styles.logo}
/>
<Androw style={styles.shadow}>
<Text style={[styles.logoText, styles.shadow]}>{NAME}</Text>
</Androw>
<Text style={styles.title}>Welcome Back</Text>
<View style={styles.subContainer}>
<ScrollView showsVerticalScrollIndicator={false}>
<Text style={styles.loginText}>Login</Text>
<View style={styles.textBox}>
<Input
// icon="email"
placeholder="Email or username"
autoCapitalize="none"
autoCompleteType="email"
value={this.state.email}
onChangeText={(txt) => this.setState({email: txt})}
/>
<View style={styles.textInput}>
<Input
// icon="pass"
placeholder="Password"
autoCapitalize="none"
autoCompleteType="password"
value={this.state.password}
onChangeText={(txt) => this.setState({password: txt})}
/>
</View>
</View>
<TouchableOpacity>
<Text style={styles.forgotPasswordText}>
Don't remember your password?
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => console.log(this.state)}>
<Button text="Login" />
</TouchableOpacity>
<Text style={styles.noAccountText}>
Don't have an account?{' '}
<Text style={styles.signupText}>Signup</Text>
</Text>
</ScrollView>
</View>
</SafeAreaView>
解决方案
你应该把你的子视图包裹在里面
<ScrollView>
<View>
.....
</View>
</ScrollView>
上衣<View>
必须有格调flex:1
。交替尝试这样做
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
...
</ScrollView>
推荐阅读
- ruby-on-rails - 在 Heroku 中将 Postgresql 连接到 Rails
- sql - 在 Where 子句中选择不返回数据
- javascript - 如何在异步等待操作中测试 catch 语句
- python - NameError 即使在上面的行上直接无条件赋值
- unity3d - 我对苹果电视上的相机有一个奇怪的问题。有白色像素化覆盖了关卡并且只显示了它的一部分
- javascript - 在功能组件中执行异步操作
- google-apps-script - 一天内服务调用次数过多:在时间触发器上仅发送了 19 封电子邮件的电子邮件
- google-sheets - 谷歌表格导入 Excel
- python - 如何阻止错误的 GPIO 触发发生?
- python - 我怎样才能保存这个文件txt?