recyclerview with match\u parent for width and height返回固定大小错误

hivapdat  于 2021-07-03  发布在  Java
关注(0)|答案(2)|浏览(792)

生成apk/签名包时,lintvitalrelease返回此报告:

<issue
    id="InvalidSetHasFixedSize"
    severity="Fatal"
    message="When using `setHasFixedSize() in an `RecyclerView`, `wrap_content` cannot be used as \&#xA;a value for `size` in the scrolling direction."
    category="Correctness"
    priority="5"
    summary="When using `setHasFixedSize() in an `RecyclerView`, `wrap_content` cannot be used as \&#xA;a value for `size` in the scrolling direction."
    explanation="When a RecyclerView uses `setHasFixedSize(...)` you cannot use `wrap_content` for  size in the scrolling direction."
    errorLine1="        recyclerView.setHasFixedSize(true);"
    errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
    <location
        file="/home/Documents/MyProject/app/src/main/java/com/myproject/MainActivity.java"
        line="97"
        column="9"/>
</issue>

这显然不是真的,因为我的布局文件如下所示:

<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:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:clipToPadding="false"
        android:overScrollMode="never"
        android:paddingTop="8dp"
        android:scrollbars="none"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

是林特错了还是我把事情搞砸了?
在我将kotlin与java项目集成之后,这就成了一个问题!

eagi6jfj

eagi6jfj1#

问题出在回收物品的布局上。不能将其设置为 Package 内容。

vmjh9lq9

vmjh9lq92#

你在代码中的错误可能是

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

在这种情况下,我们将使用my\u recycler\u view.sethasfixedsize(true)

<android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

在另一个myrecyclerview.sethasfixedsize(false)中,如果我们也使用wrap\u内容作为宽度,则这适用

相关问题