我的RecyclerView中的视图行之间出现大量随机放置的间隙,与其他用户在以下问题中提到的一样。Android RecyclerView平板电脑风景上的一些物品行后的大间隔空间
我已经看着像其他问题建议的解决方案:
Large gap forms between RecyclerView items when scrolling down
Large gap between RecyclerView items
RecyclerView items with big empty space after 23.2.0
Android RecyclerView Blank Space
RECYCLERVIEW SPACE BETWEEN ITEMS ON ANDROID APPLICATION
RecyclerView items with very large empty space at bottom after updating to support library 23.2.1
,但他们都缝建议同一件事:改变match_parent在你的布局,以WRAP_CONTENT。从布局代码可以看出,我已经尝试过了,但我仍然得到相同的差距。
我需要注意的是,这些空白仅存在于景观中的平板电脑中。
我的布局:
content_main.xml:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
content_main.xml在布局sw600pd口:在布局sw600pd
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llTwoPane"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="true"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:paddingTop="@dimen/gap_xl"
tools:context=".MainActivity">
<fragment
android:id="@+id/fragment_main"
android:name=".MainFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:layout="@android:layout/list_content" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="@integer/parts_fd"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
content_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llTwoPane"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="horizontal"
android:paddingTop="@dimen/gap_xl">
<fragment
android:id="@+id/fragment_main"
android:name=".MainFragment"
android:layout_width="0dp"
android:layout_weight="@integer/parts_fm"
android:layout_height="wrap_content"
tools:layout="@android:layout/list_content" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="@integer/parts_fd"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
fragment_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llFragmentMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainFragment"
tools:showIn="@layout/activity_main"
android:background="@color/colorGray"
>
<Spinner
android:id="@+id/spnSort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:paddingTop="@dimen/title_gap"
android:paddingBottom="@dimen/title_gap"
android:paddingLeft="@dimen/gap_m"
android:paddingRight="@dimen/gap_m"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvPosters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/half_poster_spacing"
android:background="@color/colorLight"
android:scrollbars="vertical"
android:animateLayoutChanges="false"
android:scrollbarThumbHorizontal="@drawable/scrollbar"
/>
</LinearLayout>
item.xml充气适配器:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flPosterItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/half_poster_spacing"
android:descendantFocusability="blocksDescendants"
>
<ImageView
android:id="@+id/imvPoster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/poster_content_description"
/>
<Button
android:id="@+id/btnFavouriteInMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="@dimen/fav_button_minw"
android:paddingBottom="@dimen/fav_button_padding"
android:paddingLeft="@dimen/fav_button_padding"
android:paddingStart="@dimen/fav_button_padding"
android:paddingRight="@dimen/fav_button_padding"
android:paddingEnd="@dimen/fav_button_padding"
android:background="@color/colorButtonStarBgd"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="@dimen/text_size_m"
android:layout_gravity="bottom|end"
/>
</FrameLayout>
设置我RecyclerView有:
recyclerView.setLayoutManager(posterAdapter.getGridLayoutManager());
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setAdapter(posterAdapter);
而且网格布局管理器设置有:
GridLayoutManager getGridLayoutManager() {
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, mNumberOfColumns);
gridLayoutManager.setSmoothScrollbarEnabled(true);
gridLayoutManager.setAutoMeasureEnabled(true);
gridLayoutManager.setSpanCount(mNumberOfColumns);
return gridLayoutManager;
}
电话缺口不要在任何方向。在平板电脑上,纵向只有一列。即使使用match_parent,差距也不会出现。在横向上有三到四列,即使使用wrap_content也会出现间隙,并且它总是在整行之间。
我曾试图删除
recyclerView.setHasFixedSize(true);
ridLayoutManager.setAutoMeasureEnabled(true);
- ,并只让item.xml图像(使按钮消失)
,但没有用。
有没有人有其他解释?
你能展示关于这个问题的截图吗?另外,在你的问题中包含你的'onCreateViewHolder(...)'和'onBindViewHolder(...)'。 –
它看起来与上面的前两个问题相同。 onCreateViewHolder只是膨胀item.xml并返回用这种视图创建的CustomViewHolder。除了点击监听器,在onBindViewHolder中,我使用Glide.with(context).load(posterUrl).placeholder(placeholder).into(customViewHolder.imvPoster);.看到我的答案。 – Vlad
你使用什么版本的支持库? –