嵌套的ConstraintLayouts中的ListView不是滚动

时间:2018-05-31 07:17:22

标签: android listview android-constraintlayout

这是我关于Stack-overflow的第一个问题。

我的布局需要屏幕底部的列表视图。完整布局在Constraint Layout中设计。 列表视图也放在约束布局中。但是,它不滚动。

这是一个用于纠正的代码,因此我无法进行太多修改以使List View工作。

有些人可能认为这是一个重复的问题,但在列表视图上只有1或2个答案,并且约束布局并且解决方案也没有帮助。我搜索了很多,但没有任何作用。

欢迎任何帮助。

    

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/cl_recent_memos_top_heading"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/gray">

                <ImageView
                    android:id="@+id/img_recent_memos_top_heading_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/space_10"
                    android:layout_marginLeft="@dimen/space_10"
                    android:layout_marginTop="@dimen/space_10"
                    android:src="@drawable/applied_leaves_top"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/tv_recent_top_heading_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/space_10"
                    android:layout_marginLeft="@dimen/space_10"
                    android:layout_marginTop="@dimen/space_10"
                    android:fontFamily="serif"
                    android:text="@string/recent"
                    android:textColor="@color/dark_gray"
                    android:textSize="@dimen/top_heading_first_label_text_size"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toRightOf="@id/img_recent_memos_top_heading_bar"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/tv_memos_top_heading_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="@dimen/space_10"
                    android:layout_marginLeft="@dimen/space_10"
                    android:layout_marginTop="@dimen/space_13"
                    android:fontFamily="serif"
                    android:text="@string/memos"
                    android:textColor="#c5c5c5"
                    android:textSize="@dimen/top_heading_first_second_text_size"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toRightOf="@id/tv_recent_top_heading_bar"
                    app:layout_constraintTop_toTopOf="parent" />
            </android.support.constraint.ConstraintLayout>
        </android.support.constraint.ConstraintLayout>

        <android.support.constraint.ConstraintLayout
            android:id="@+id/cl_recent_memos_grid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="0dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@id/cl_recent_memos_top_heading">

            <android.support.constraint.ConstraintLayout
                android:id="@+id/cl_recent_memos_grid_header"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/space_5"
                app:layout_constraintLeft_toLeftOf="parent">

                <android.support.constraint.ConstraintLayout
                    android:id="@+id/cl_container_header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.constraint.ConstraintLayout
                        android:id="@+id/cl_memo"
                        android:layout_width="180dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/space_1"
                        android:background="#31cbe5"
                        app:layout_constraintLeft_toLeftOf="parent"
                        app:layout_constraintTop_toTopOf="parent">

                        <TextView
                            android:id="@+id/tv_memo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="serif"
                            android:paddingLeft="@dimen/space_3"
                            android:text="@string/memo"
                            android:textColor="@color/white"
                            android:textSize="@dimen/show_applied_leave_grid_header_label_text_size"
                            app:layout_constraintLeft_toLeftOf="parent" />
                    </android.support.constraint.ConstraintLayout>

                    <android.support.constraint.ConstraintLayout
                        android:id="@+id/cl_memo_date"
                        android:layout_width="100dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/space_1"
                        android:background="#31cbe5"
                        app:layout_constraintLeft_toRightOf="@id/cl_memo">

                        <TextView
                            android:id="@+id/tv_memo_date"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="serif"
                            android:paddingLeft="@dimen/space_3"
                            android:text="@string/memo_date"
                            android:textColor="@color/white"
                            android:textSize="@dimen/show_applied_leave_grid_header_label_text_size" />
                    </android.support.constraint.ConstraintLayout>

                    <!-- To -->
                    <android.support.constraint.ConstraintLayout
                        android:id="@+id/cl_document"
                        android:layout_width="140dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/space_1"
                        android:background="#31cbe5"
                        android:paddingLeft="@dimen/space_3"
                        app:layout_constraintLeft_toRightOf="@id/cl_memo_date">

                        <TextView
                            android:id="@+id/tv_document"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:fontFamily="serif"
                            android:text="@string/document"
                            android:textColor="@color/white"
                            android:textSize="@dimen/show_applied_leave_grid_header_label_text_size" />
                    </android.support.constraint.ConstraintLayout>

                    <!-- Edit -->
                    <android.support.constraint.ConstraintLayout
                        android:id="@+id/cl_edit"
                        android:layout_width="50dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/space_1"
                        android:background="#31cbe5"
                        app:layout_constraintLeft_toRightOf="@+id/cl_document">

                        <TextView
                            android:id="@+id/tv_edit"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/edit"
                            android:textColor="#fff"
                            android:textSize="@dimen/show_applied_leave_grid_header_label_text_size" />

                    </android.support.constraint.ConstraintLayout>

                    <!-- Delete -->
                    <android.support.constraint.ConstraintLayout
                        android:id="@+id/cl_delete"
                        android:layout_width="50dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/space_1"
                        android:background="#31cbe5"
                        app:layout_constraintLeft_toRightOf="@+id/cl_edit">

                        <TextView
                            android:id="@+id/tv_delete"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/delete"
                            android:textColor="#fff"
                            android:textSize="@dimen/show_applied_leave_grid_header_label_text_size" />

                    </android.support.constraint.ConstraintLayout>

                </android.support.constraint.ConstraintLayout>

            </android.support.constraint.ConstraintLayout>

            <android.support.constraint.ConstraintLayout
                android:id="@+id/cl_recent_memo_list"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginLeft="@dimen/space_5"
                app:layout_constraintLeft_toLeftOf="parent"
               app:layout_constraintTop_toBottomOf="@id/cl_recent_memos_grid_header">

                <ListView
                    android:id="@+id/lv_recent_memos"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:divider="@android:color/transparent"
                    android:fadeScrollbars="false" />

            </android.support.constraint.ConstraintLayout>

        </android.support.constraint.ConstraintLayout>
    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,即ListView不在ConstraintLayout中滚动。对我来说,解决方案是将ListView设置为具有顶部和底部约束的 upper

示例

// Component related to methods for sorting, pagination  server side and filtering manual filtering with in the grid

import React from 'react'
import 'react-table/react-table.css'
import ReactTable from 'react-table'
import autoBind from 'react-autobind'
import {filterCaseInsensitive} from '../../helper/commonMethods'


class ServerSideAtomGrid extends React.Component {

super(props)
    const userDetails = getUserDetails()
    this.state = {

      page: 0,
      pageSizeOptions: [500, 1000, 2000, 4000],
      pageSize: 500,
      totalRecords: 0,
      nextCursor: '*',
      cursorList: [{
        page: 0,
        cursor: '*'
      }],
      sortFields: {
        field: 'created_dtm',
        sort: 'desc'
      },
      columnData,
    }
    autoBind(this)
  }
  handlePageChange (page) {
    const pageNumber = (page)
    const cursorList = this.state.cursorList
    let cusrsorMark = ''
    _.each(cursorList, (list) => {
      if (list.page === pageNumber) {
        cusrsorMark = list.cursor
      }
    })
    this.setState({
      nextCursor: cusrsorMark,
      page: pageNumber
    }, () => this.searchData(cusrsorMark, pageNumber))
  }
  handleSizePerPageChange (pageSize) {
    this.resetData(pageSize)
    this.searchData('*', 0)
  }
  handleSorting = (state, instance) => {
    const sorted = state
    let field = 'created_dtm'
    let sort = 'desc'
    sorted && sorted.length > 0 && sorted.map(fld => {
      field = fld.id
      sort = fld.desc ? 'desc' : 'asc'
    })
    this.setState({
      sortFields: {
        field,
        sort
      }
    }, () => this.searchData('*', 0))
  }
  ////
 searchData('*', 0) {
    //Axios call you cna have 
 }
 filterCaseInsensitive (filter, row) {
  const id = filter.pivotId || filter.id
  return row[id] ? row[id].toString().toLowerCase().includes(filter.value.toLowerCase()) : true
}
  render () {
    const {
      classes, gridData, gridColumns, defaultFilter, totalRecords,
      gridPageSizeOptions, gridPage, gridPages, gridPageSize, gridLoading
    } = this.props
    return (
      <div>
        <ReactTable
          columns={gridColumns}
          data={gridData}
          onSortedChange={(state, instance) => {
            this.handleSorting(state, instance)
          }}
          filterable={defaultFilter}
          defaultFilterMethod={filterCaseInsensitive}
          noDataText="Ops No result found!"
          defaultPageSize={this.state.pageSize}
          className="-highlight"
          style={{height: `${totalRecords < 25 ? '' : `800px`}`, width: '100%', textAlign: 'center'}}
          pageText={`Total Count : ${totalRecords.toLocaleString()} Page: `}
          loading={gridLoading}
          page={this.state.page}
          pages={this.state.pages}
          showPaginationTop
          pageSize={this.state.pageSize}
          pageSizeOptions={gthis.state.pageSizeOptions}
          minRows={25}
          manual
          onPageChange={page => {
             this.setState({page})
             this.handlePageChange(page)
          }}
          onPageSizeChange={(pageSize, page) => {
          this.setState({
                    page,
                    pageSize
                  })
            this.props.handleSizePerPageChange(pageSize)
          }}
          showPageJump={false}
        />
      </div>
    )
  }
}

export default (ServerSideAtomGrid)