Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使回收器视图垂直滚动_Java_Android_User Interface_Android Recyclerview_Android Constraintlayout - Fatal编程技术网

Java 使回收器视图垂直滚动

Java 使回收器视图垂直滚动,java,android,user-interface,android-recyclerview,android-constraintlayout,Java,Android,User Interface,Android Recyclerview,Android Constraintlayout,我正在使用以下代码创建一个回收器视图。recyclerview有一个网格布局管理器,每行最多有2个项目 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

我正在使用以下代码创建一个回收器视图。recyclerview有一个网格布局管理器,每行最多有2个项目

 <androidx.constraintlayout.widget.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="match_parent"
        android:background="@color/white"
        android:clickable="true"
        android:focusableInTouchMode="true"
        android:focusable="true">

    <ImageView
        android:id="@+id/backPress"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/hello"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Title!"
        android:textSize="30sp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        />

    <TextView
        android:id="@+id/textGoing"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Subtitle"
        android:textSize="@dimen/text_average"
        android:textStyle="bold"
        app:layout_constraintTop_toBottomOf="@+id/hello" />
    <com.google.android.material.textfield.TextInputLayout
        android:layout_margin="@dimen/dimen_20"
        app:layout_constraintTop_toBottomOf="@+id/textGoing"
        android:id="@+id/anchor_input"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:boxBackgroundColor="@android:color/white"
        android:background="@android:color/transparent" >

        <EditText
            android:id="@+id/anchor_edit_txt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        app:layout_constraintTop_toBottomOf="@+id/anchor_input"
        app:layout_constraintStart_toStartOf="@+id/anchor_input"
        android:id="@+id/anchor_hint"
        android:layout_below="@+id/anchor_input"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />


    <Button
        android:id="@+id/add_cat_btn"
        app:layout_constraintTop_toBottomOf="@+id/anchor_hint"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_below="@+id/anchor_hint"
        android:layout_marginTop="@dimen/dimen_20"
        android:text="START"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"/>

    <TextView
        android:id="@+id/category_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/add_cat_btn"
        android:text="Description"/>
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/category_rv"
        app:layout_constraintTop_toBottomOf="@+id/category_title"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
        tools:itemCount="4"
        android:layout_margin="@dimen/dimen_20"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/move_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabSize="normal"
        app:tint="@android:color/white"
        app:layout_constraintEnd_toEndOf="@+id/category_rv"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

不幸的是,我嵌套在ConstraintLayout中的recycler视图根本没有滚动。我错过了什么?约束布局是否支持相同的设置?

错误来自

tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:itemCount="4"
换成

app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="4"
错误来自于

tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:itemCount="4"
换成

app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="4"

要使用ConstraintLayout parent解决RecyclerView滚动问题,请将RecyclerView高度从wrap_内容更改为0dp,并添加顶部和底部约束,如下所示:

<androidx.recyclerview.widget.RecyclerView
   android:id="@+id/category_rv"
   android:layout_width="0dp"
   android:layout_height="0dp"
   app:layout_constraintStart_toStartOf="parent"
   app:layout_constraintEnd_toEndOf="parent"
   app:layout_constraintTop_toBottomOf="@+id/category_title"
   app:layout_constraintBottom_toBottomOf="parent"/>

要解决带有ConstraintLayout父级的RecyclerView滚动问题,请将RecyclerView高度从wrap_内容更改为0dp,并添加顶部和底部约束,如下所示:

<androidx.recyclerview.widget.RecyclerView
   android:id="@+id/category_rv"
   android:layout_width="0dp"
   android:layout_height="0dp"
   app:layout_constraintStart_toStartOf="parent"
   app:layout_constraintEnd_toEndOf="parent"
   app:layout_constraintTop_toBottomOf="@+id/category_title"
   app:layout_constraintBottom_toBottomOf="parent"/>


这是否回答了您的问题?不我试过了。。这不起作用上面链接的问题看起来像问题:你的回收视图的高度是
wrap\u content
。你到底想换什么?这能回答你的问题吗?不我试过了。。这不起作用上面链接的问题看起来像问题:你的回收视图的高度是
wrap\u content
。您到底尝试更改了什么?我按照您的建议替换了所有内容,但出现了错误persistsCan您在将适配器连接到recyclerview的位置添加了适配器代码和活动代码?我按照您的建议替换了所有内容,但出现了错误persistsCan您在将适配器连接到recyclerview的位置添加了适配器代码和活动代码回收视图?