简体   繁体   English

ScrollView 在其中包含 View 组件时无法滚动

[英]ScrollView cannot scroll when having View components inside of it

I am using React Native:我正在使用 React Native:
I have a components called inside of a ScrollView :我有一个在ScrollView内部调用的组件:

function SomeScreen(){

    return(

        <ScrollView style={myStyles.someStyles}>

            <View>
                <Text style={myStyles.homeHeroTitle}>Hello Tom</Text>
                <Text>It's great seeing you!</Text>
            </View>


            <View>
                <Text>SomeText</Text>
            </View>
            
            <View>
                <Text>SomeOtherText</Text>
            </View>
    
        </ScrollView>   
    );
    
}


let myStyles = StyleSheet.create({
   someStyles:{
      width: "100%",
      height: "100%",
      
   },
});

I cannot scroll in the ScrollView, when I am calling other View elements inside of the ScrollView.我不能在滚动型滚动,当我打电话了滚动内其他视图元素

But, I can scroll when the only elements inside of the ScrollView are the Text element.但是,当ScrollView中的唯一元素是Text元素时,我可以滚动。

在滚动视图的样式中使用 flex:1 并尝试为滚动添加更多文本(添加数据)。

Firstly, try to avoid so many Views as Text also have properties of View which you can use.首先,尽量避免使用过多的视图,因为文本也具有您可以使用的视图属性。

Secondly, you can give styling to ScrollView as其次,您可以为 ScrollView 设置样式

someStyles:{
flex:1
}

It depends on, from where you imported ScrollView.Is it from react-native or react-native-gesture-handler?这取决于您从何处导入 ScrollView。是从 react-native 还是 react-native-gesture-handler?

import { ScrollView } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM