You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中使用KeyboardAvoidingView和多FlatList时视图缩小问题

问题求助:React Native Android平台KeyboardAvoidingView下FlatList视图缩小问题

iOS与Android视图差异

我开发了一个包含KeyboardAvoidingView的页面,内部设有一个TextInput和两个FlatList。设计目标是让两个FlatList各占据屏幕45%的空间,并且支持滚动。

该实现在iOS平台上运行正常,但在Android平台上视图会莫名缩小。

可复现简化代码

const RandomTest: React.FC<NavigationProps> = ({ navigation }) => {
    const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
    return (
        <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={{ flex: 1 }}>
            <View style={{ flex: 0.1 }}>
                <TextInput
                    style={{ flex: 0.7, borderWidth: 1, borderColor: AppColors.green, borderRadius: 10 }}
                    placeholder="Placeholder"
                    value={'random'}
                    onChangeText={(input) => {}}
                />
            </View>
            <View style={{ flex: 0.45 }}>
                <FlatList
                    style={styles.flatList}
                    contentContainerStyle={{ alignItems: 'center', justifyContent: 'flex-end' }}
                    data={data}
                    nestedScrollEnabled={true}
                    renderItem={({ item }) => (
                        <View style={{ height: 50 }}>
                            <Text>Test</Text>
                        </View>
                    )}
                />
            </View>

            <View style={{ flex: 0.45 }}>
                <FlatList
                    style={styles.flatList}
                    contentContainerStyle={{ alignItems: 'center', justifyContent: 'flex-end' }}
                    data={data}
                    nestedScrollEnabled={true}
                    renderItem={({ item }) => (
                        <View style={{ height: 50 }}>
                            <Text>test</Text>
                        </View>
                    )}
                />
            </View>
        </KeyboardAvoidingView>
    );
};

问题演示视频如下:

内容的提问来源于stack exchange,提问作者AsMartynas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 21:06:36