css - 当 View 放置在 ScrollView 中以进行原生 react 时,为什么 flexDirection 不起作用?

标签 css react-native flexbox scrollview

当 View 放置在 ScrollView 中以进行原生 react 时,为什么 flexDirection 不起作用?

enter image description here

当我的 View 未放置在 ScrollView 中时,参数 flexDirection: 'row' 工作正常。

export default class ProfileScreen extends Component {
render() {
    return (
            <View style={{flex: 0.1, flexDirection: 'row', justifyContent: 'flex-start', height:70}}>
                <View style={{flex:0.2, backgroundColor: 'red'}} />
                <View style={{flex:0.8, backgroundColor: 'skyblue'}} />
                <View style={{flex:0.2, backgroundColor: 'steelblue'}} />
            </View>
    );
}

当它被放置在 ScrollView 中时,参数 flexDirection 不再起作用。
export default class ProfileScreen extends Component {
render() {
    return (
        <ScrollView stickyHeaderIndices={[0]} >
            <View style={{flex: 0.1, flexDirection: 'row', justifyContent: 'flex-start', height:70}}>
                <View style={{flex:0.2, backgroundColor: 'red'}} />
                <View style={{flex:0.8, backgroundColor: 'skyblue'}} />
                <View style={{flex:0.2, backgroundColor: 'steelblue'}} />
            </View>
            <View style={{flex: 1, flexDirection: 'row', height: 10}} />
            <View style={{flex: 1, flexDirection: 'row', height: 200, backgroundColor: 'skyblue'}} />
            <View style={{flex: 1, flexDirection: 'row', height: 10}} />
        </ScrollView>
    );
}
}

enter image description here

最佳答案

我遇到了这个问题。

想想发生了什么,stickyHeaderIndices覆盖受影响 View 中的一些样式。
简单地包装你想要坚持的 View 将解决问题,即

...
  <ScrollView stickyHeaderIndices={[0]} >
    <View>
      <View style={{flex: 0.1, flexDirection: 'row', ... }}>
         <View style={{flex:0.2, backgroundColor: 'red'}} />
         <View style={{flex:0.8, backgroundColor: 'skyblue'}} />
         <View style={{flex:0.2, backgroundColor: 'steelblue'}} />
       </View>
    </View>
    
   ...
   </ScrollView>

关于css - 当 View 放置在 ScrollView 中以进行原生 react 时,为什么 flexDirection 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49149045/

相关文章:

react-native - Expo sound,如何获得声音的持续时间

javascript - React Native - 如何更好地调试 javascript 代码?

reactjs - 在 React Native ios 应用程序中无法识别 fontFamily

html - 在 flex box 中使用时,网格不占据其 div 的全部高度

css - "flex"和 "justify-content"可以实现 "text-align"不能实现的功能?

javascript - 在窗口调整大小时保持原始高度比的 Flexbox 行

css - 如何在 ionic framework v4 和 Angular 7 中调整图标大小

javascript - 通过单击元素内的 anchor 或包含 div id 的任何位置将元素滚动到页面顶部

javascript - 使用 jQuery 动态更改链接

javascript - jquery-mobile:关闭桌面主题