【问题标题】:How to let content of scrollView align top in react-native如何让 scrollView 的内容在 react-native 中对齐顶部
【发布时间】:2017-05-15 08:54:00
【问题描述】:

我有一个scrollView,并且scrollView中有List,但是它的行为顶部总是存在一个空白,我想要scrollView的内容对齐顶部,但是无论我做什么,它都不起作用,是有谁知道怎么做?

代码

const { height } = Dimensions.get('window') //eslint-disable-line

const list = SIDEBAR_LINKS

const styles = {
  containerStyle: {
    borderBottomWidth: 0,
  },
  wrapperStyle: {
    paddingLeft: 43,
  },
  scrollView: {
    height,
    backgroundColor: '#000000',
    flex: 1
  }
}



//@observer
const SideBar = observer(({ store }) => {

  const { containerStyle, wrapperStyle, scrollView } = styles

  return(
    <ScrollView style = {scrollView} contentContainerStyle={{flexGrow: 1}}>
      <List style = {{backgroundColor: '#ff0000', flex: 1, paddingTop: 100, justifyContent: 'flex-start'}}>
        <ListItem
            containerStyle={{ height: 43, backgroundColor: '#F5F5F5', borderBottomWidth: 0.5, borderBottomColor: '#BDBDBD'}}
            rightIcon={{ name: 'menu', color: 'black' }}            
        />
        <ListItem
            roundAvatar
            containerStyle={containerStyle}
            avatar={ store.user.photoURL }
            title={ store.user.displayName }   
        />
        {
          list.map((item, i) => (
              <ListItem
                key={i}
                containerStyle={containerStyle}
                wrapperStyle={wrapperStyle}
                underlayColor={'#f8f8f8'}
                title={item.title}
                leftIcon={{ name: item.icon }}
                badge={false}
              />
          ))
        }
      </List>
    </ScrollView>
  )
 }

图片

【问题讨论】:

    标签: javascript css reactjs react-native react-native-android


    【解决方案1】:

    尝试使用:

      containerStyle: {
        borderBottomWidth: 0,
        flex: 1,
        flexDirection: 'column',
        justifyContent: 'flex-start',
      },
    

    根据您的喜好,请阅读 react-native 的 flex-box 教程:

    https://facebook.github.io/react-native/docs/flexbox.html

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 2021-10-07
      • 1970-01-01
      • 2023-04-02
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      相关资源
      最近更新 更多