【问题标题】:Trouble with scroll in view (GridLayot + GridView)视图中的滚动问题(GridLayot + GridView)
【发布时间】:2019-03-11 14:04:55
【问题描述】:

我在以下视图中的滚动有一些问题

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:isScrollContainer="true">

    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/mainGrid"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnCount="3"
                android:layout_margin="0dp"
                android:orientation="horizontal"
                android:layout_marginBottom="4dp">

        <!-- Card number block start -->
        <TextView
                android:layout_columnSpan="2"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:hint="Card number"/>
        <!-- Card number block end -->

        <!-- same other blocks -->

        <!-- Contact list block start -->
        <GridView
                android:layout_columnSpan="3"
                android:id="@+id/tableContacts"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="fill"
                tools:ignore="MissingConstraints"
                app:layout_constraintTop_toBottomOf="@+id/btnAddNewContact"/>
        <!-- Contact list block end -->

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

如果联系人列表很长,则视图不可滚动。如果我在ScrollView 中插入GridLayout,那么GridView 会折叠成一行并添加一个内部滚动。

android:isScrollContainer="true" 没有帮助。

我无法选择如何添加滚动,以免GridView 折叠

【问题讨论】:

  • 试试这个解决方案(在 LinearLayout 上使用 ScrollView)是否也适用于 GridLayout:stackoverflow.com/questions/4055537/…
  • 有人已经在 StackOverflow 中问过这个问题。这是链接:stackoverflow.com/questions/10610943/gridlayout-scrollview
  • @acarlstein 首先-看下帖子,其次-您不专心,结构更复杂,因此存在问题
  • 所以...您尝试了&lt;ScollView&gt;&lt;LinearLayout&gt;&lt;GridLayout&gt;...&lt;/GridLayout&gt;&lt;/LinearLayout&gt;&lt;/ScollView&gt;,但没有成功。这就是你说的。
  • 找到solution trouble。这对我有用

标签: android android-layout gridview scroll grid-layout


【解决方案1】:

据了解,ScrollView 组件只需要一个子组件。尝试将包括 GridLayout 在内的所有内容包装在一个 LinearLayout 中。

【讨论】:

  • 它不起作用我已经试过了 - scroll->linear->block*n 和 scroll->linear->(linear->block)*n
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-03
相关资源
最近更新 更多