Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.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
Android RecyclerView平板电脑上几行物品后的大间隙空间_Android_Android Recyclerview_Tablet_Spacing - Fatal编程技术网

Android RecyclerView平板电脑上几行物品后的大间隙空间

Android RecyclerView平板电脑上几行物品后的大间隙空间,android,android-recyclerview,tablet,spacing,Android,Android Recyclerview,Tablet,Spacing,我的RecyclerView中的视图行之间出现了大量随机放置的间隙,这与下面问题中提到的其他用户相同 我已经研究了其他问题的建议解决方案,如: 但它们都有相同的建议:将match\u parent更改为在布局中包装内容。从下面的布局代码可以看出,我已经尝试过了,但仍然有相同的差距 我需要注意的是,这些差距只存在于平板电脑的景观 我的布局: content_main.xml: <FrameLayout xmlns:android="http://schemas.andro

我的RecyclerView中的视图行之间出现了大量随机放置的间隙,这与下面问题中提到的其他用户相同

我已经研究了其他问题的建议解决方案,如:

但它们都有相同的建议:将match\u parent更改为在布局中包装内容。从下面的布局代码可以看出,我已经尝试过了,但仍然有相同的差距

我需要注意的是,这些差距只存在于平板电脑的景观

我的布局:

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"
    />
<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>
网格布局管理器设置为:

GridLayoutManager getGridLayoutManager() {
    GridLayoutManager gridLayoutManager = new GridLayoutManager(context, mNumberOfColumns);
    gridLayoutManager.setSmoothScrollbarEnabled(true);
    gridLayoutManager.setAutoMeasureEnabled(true);
    gridLayoutManager.setSpanCount(mNumberOfColumns);
    return gridLayoutManager;
}
在手机上,间隙不会以任何方向出现。在平板电脑上,肖像只有一列。即使使用match_parent,间隙也不会出现。在横向视图中,有三到四列,即使有换行内容,也会出现间隙,并且总是在整行之间

我试着把它去掉

  • recyclerView.setHasFixedSize(true)
  • ridLayoutManager.setAutoMeasureEnabled(true)
  • 和仅生成item.xml图像(使按钮消失)
但是没有用


有人有其他解释吗?

如上文提到的其他问题的答案所述,将“匹配父项”更改为“包装内容”应该可以解决问题。但事实并非如此,如果有人能解释为什么我会接受这个答案


我已经解决了这一问题,方法是反向匹配RecyclerView和相关布局高度的父项,并为
GridLayoutManager
设置
setAutoMeasureEnabled(false)
(上述
getGridLayoutManager()
函数的第三行-刚刚将
true
更改为
false
).

能否显示有关该问题的屏幕截图?另外,在您的问题中包括您的
onCreateViewHolder(…)
onBindViewHolder(…)
。它看起来与上面的前两个问题相同。onCreateViewHolder只是膨胀item.xml并返回使用该视图创建的CustomViewHolder。除了单击listener,在onBindViewHolder中我使用Glide.with(context).load(posterUrl).placeholder(placeholder).into(customViewHolder.imvPoster);。看看我的答案。你使用什么版本的支持库?@gergelykőrössy-v7I的意思是23.2.0等等。
<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>
<?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.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;
}