反应本地滚动视图不会在Android中滚动

时间:2019-06-06 09:06:00

标签: react-native

scrollview在ios中有效,但在android中不可用

import React from 'react';
import {
    ScrollView,
    StyleSheet,
    Text,
    View,
} from 'react-native';
export default class HomeScreen extends React.Component {
    render() {
        return (        
            <ScrollView style={css.outside} contentContainerStyle={css.contentContainer}>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
            </ScrollView>       
        )
    }   
}

const css = StyleSheet.create({
    outside :{

        flex:1,
    },
    contentContainer: {

        paddingTop: 30,
    },
});

小吃:https://snack.expo.io/@cosmo/simple-scroll

2 个答案:

答案 0 :(得分:2)

您没有足够的内容。添加更多内容或尝试以下提供的内容,以确认它在android中工作正常。

import React from 'react';
import {
    ScrollView,
    StyleSheet,
    Text,
    View,
} from 'react-native';
export default class HomeScreen extends React.Component {
    render() {
        return (        
      <View style={{height: 150}}>
        <ScrollView contentContainerStyle={css.contentContainer}>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
                <Text>some text</Text>
            </ScrollView>       
      </View>

        )
    }   
}

const css = StyleSheet.create({
    contentContainer: {
        paddingTop: 30,
    },
});

答案 1 :(得分:0)

在您的contentContainerStyle中尝试用flexGrow:1代替flex:1