滚动视图内部视图不起作用反应原生 [英] Scroll View inside view not working react native
问题描述
在这里,我正在尝试一个简单的代码,但如果将滚动视图保存在另一个视图中,则它不起作用.代码是这样的:
Here I am trying a simple code but the scroll view is not working if kept inside another view. Code is like this:
return(
<View>
<Toolbar title={this.props.title}>
</Toolbar>
<ScrollView>
<HomeScreenTop />
<HomeScreenBottom navigator={navigator}/>
</ScrollView>
</View>
);
但是如果滚动视图保持为父视图,它就可以完美运行.代码如下:
But if scroll view kept as parent view it works perfectly. Code is as below:
return(
<ScrollView>
<Toolbar title={this.props.title}>
</Toolbar>
<HomeScreenTop />
<HomeScreenBottom navigator={navigator}/>
</ScrollView>
);
现在的问题是我不想让我的工具栏上下滚动,我只想让工具栏下方的内容移动.我怎样才能做到这一点?
Now the problem is I don't want my toolbar to scroll up and down, I just want the contents below the toolbar to move. How can I achieve that?
下一个问题:滚动视图是否必须是父视图才能返回工作?
And next question: Is scroll view has to be parent view to be returned to work?
推荐答案
你应该像这样在视图中包裹工具栏:
you should wrap toolbar in view like this:
<View><Toolbar/></View>
将要在滚动视图中滚动的组件包装为:
Wrap those component which you want to scroll inside scrollview as:
<ScrollView>your expected components...</ScrollView>
并为根视图提供 flex 为:
And provide flex to root view as:
<View style={{flex:1}}>
最后,您的代码将按预期运行.
Finally your code will run as you expected.
这篇关于滚动视图内部视图不起作用反应原生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!