【问题标题】:React native ListView is not scrolling反应本机 ListView 不滚动
【发布时间】:2016-02-29 14:59:31
【问题描述】:

我正在使用 react native 编写应用程序。它有一个 ListView 来显示项目列表。我的代码如下所示:

var ListMoviesView = React.createClass({

getInitialState() {
    return {
        dataSource: new ListView.DataSource({
            rowHasChanged: (row1, row2) => row1 !== row2
        }),
        loaded: false
    };
},

componentDidMount : function() {
    this.fetchData();
},



render : function() {
    if (!this.state.loaded) {
        return this.renderLoadingView();
    }

    return(

          <ListView
               dataSource={this.state.dataSource}
               renderRow={this.renderMovie}
               style={styleList.listView} />
    );
},

renderMovie(movie) {
    return (
        <View style={styleList.container}>
            <Image source={{uri: movie.posters.thumbnail}} style={styleList.thumbnail} />
        </View>
    );
},

buttonClicked : function (movie){
}


});

列表滚动效果很好。但如果我有一个这样的 ToolbarAndroid:

    return(
        <View>
            <ToolbarAndroid
                actions={toolbarActions}
                onIconClicked={() => this.setState({actionText: 'Icon clicked'})}
                style={styleToolbar.toolbar}
                subtitle={this.state.actionText}
                title="Toolbar" />
            <ListView
                dataSource={this.state.dataSource}
                renderRow={this.renderMovie}
                style={styleList.listView} />
        </View>
    );

ListView 没有滚动。我忘记了什么?

我的风格:

toolbar: {
    backgroundColor: '#e9eaed',
    height: 56
}


listView: {
    flexDirection: 'column',
    flex:1,
    backgroundColor: '#F5FCFF'
}

我尝试添加容器 ViewScrollView,但这也不起作用。

【问题讨论】:

    标签: listview react-native


    【解决方案1】:

    你应该添加一个样式到 喜欢:

    <View style={styles.container}>
       <ToolbarAndroid />
       <ListView />
    </View>
    

    风格:

    container:{
    flex:1,
    }
    

    我不知道为什么,但它起作用了。

    【讨论】:

      猜你喜欢
      • 2018-08-21
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      相关资源
      最近更新 更多