#java #android #android-layout #android-recyclerview
#java #Android #android-макет #android-recyclerview
Вопрос:
При создании пакета APK / Signed lintVitalRelease возвращает этот отчет:
<issue
id="InvalidSetHasFixedSize"
severity="Fatal"
message="When using `setHasFixedSize() in an `RecyclerView`, `wrap_content` cannot be used as amp;#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 amp;#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>
Является ли lint неправильным или я что-то напутал?
это стало проблемой после того, как я интегрировал kotlin со своим Java-проектом!
Комментарии:
1. Попробуйте App Bundle вместо apk, поскольку apk не требуется для загрузки в play Store, он не выдает никаких ошибок.
2. Вы решили эту проблему? Я буквально удалил все экземпляры wrap_content / 0dp из своих макетов и все еще вижу это…
3. @sinek Проблема была с Android Studio / lint. Я не помню, как я это исправил, но попробуйте сбросить кеш.
Ответ №1:
Возможно, ваша ошибка в коде может быть такой
<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_recycler_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"/>
И в этом другом моем recyclerview.setHasFixedSize (false) это применимо, если мы также используем wrap_content в качестве width