我使用带有无限滚动的回收器网格视图。我在回收器视图最后一项上遇到了新问题。在第一次加载最后一个列表最后一项时需要额外的空间。当滚动顶部并再次返回相同的位置时,它会自动分配正确的空间。我添加了我的问题快照并添加了我的 xml 文件。请查看并解释什么问题?
我的主要 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear_detail_list_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/SIZE_5"
android:background="@color/white"
android:orientation="vertical"
tools:context="com.own.ecommerce.ui.activities.ProductDetailsListActivity">
<LinearLayout
android:id="@+id/linear_list_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/SIZE_5"
android:layout_marginEnd="@dimen/SIZE_10"
android:layout_marginStart="@dimen/SIZE_10"
android:layout_marginTop="@dimen/SIZE_10"
android:background="@drawable/bg_border"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="@+id/img_list_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1"
android:contentDescription="@null"
android:src="@drawable/ic_list_view" />
<LinearLayout
android:id="@+id/linear_detail_grid_sorting"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_start_product_detail_5"
android:layout_weight="0.45"
android:background="@drawable/bg_border"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/padding_product_detail_5"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:contentDescription="@null"
android:src="@drawable/ic_sort" />
<TextView
style="@android:style/TextAppearance.Small"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="@string/action_sorting" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear_detail_grid_filter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.45"
android:gravity="center"
android:orientation="horizontal"
android:padding="@dimen/padding_product_detail_5"
android:weightSum="1">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:contentDescription="@null"
android:src="@drawable/ic_filter" />
<TextView
style="@android:style/TextAppearance.Small"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="@string/action_filter" />
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_grid_product_detail_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/SIZE_10"
android:layout_marginStart="@dimen/SIZE_10"
android:background="@color/white"
android:scrollbars="none" />
</LinearLayout>
我的适配器类 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/linear_grid_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_border"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.own.ecommerce.view.SquareImageView
android:id="@+id/img_grid_product"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7" />
<TextView
android:id="@+id/tv_grid_product"
style="@android:style/TextAppearance.Small"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginEnd="@dimen/SIZE_10"
android:layout_marginStart="@dimen/SIZE_10"
android:layout_weight="0.1"
android:background="@color/white"
android:gravity="start|center"
android:lines="2"
android:textColor="@color/black" />
<TextView
android:id="@+id/tv_grid_product_price"
style="@android:style/TextAppearance.Small"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/SIZE_10"
android:layout_marginStart="@dimen/SIZE_10"
android:layout_weight="0.1"
android:background="@color/white"
android:gravity="start|center"
android:lines="1"
android:textColor="@color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="0.1"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="@dimen/SIZE_10"
android:weightSum="1">
<Button
android:id="@+id/btn_grid_buy"
style="@android:style/TextAppearance.Small"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.80"
android:background="@color/black"
android:text="@string/nav_frag_home_grid_btn_name"
android:textColor="@color/white" />
<ImageView
android:id="@+id/img_grid_buy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.20"
android:background="@color/light_black"
android:contentDescription="@null"
app:srcCompat="@mipmap/ic_cart" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
我的问题图片:
在第一次加载时,
我如何解决这个问题?