在RecyclerView中的android – GridLayoutManager 3列

在RecyclerView中的android – GridLayoutManager 3列,第1张

概述我正在尝试使用3列创建简单的GridLayout,但是虽然我得到3列,但行之间会出现奇怪的差距.所以,我得到的行中有3个图像,而不是一行是空的(它看起来高度匹配行abov的高度(有图像),然后是3行图像的行,而不是奇怪的间隙……等等.我预计不会得到比空白差距.如何删除这个空白差距?尝试在回收器视图上将wrap_content设置为layout_height,片段没有帮助. 这是我的代码: fina 我正在尝试使用3列创建简单的GrIDLayout,但是虽然我得到3列,但行之间会出现奇怪的差距.所以,我得到的行中有3个图像,而不是一行是空的(它看起来高度匹配行abov的高度(有图像),然后是3行图像的行,而不是奇怪的间隙……等等.我预计不会得到比空白差距.如何删除这个空白差距?尝试在回收器视图上将wrap_content设置为layout_height,片段没有帮助.
这是我的代码:

final GrIDLayoutManager layoutManager = new GrIDLayoutManager(this,3);    layoutManager.setorIEntation(linearlayoutmanager.VERTICAL);    recyclerVIEw.setLayoutManager(layoutManager);    recyclerVIEw.setAdapter(adapter);

这是活动的xml:

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent"androID:layout_height="match_parent" androID:paddingleft="@dimen/activity_horizontal_margin"androID:paddingRight="@dimen/activity_horizontal_margin"androID:paddingtop="@dimen/activity_vertical_margin"androID:paddingBottom="@dimen/activity_vertical_margin"tools:context="com.adriagate.adriagateonlineandroID.activitIEs.ImagesActivity"><fragment xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools" androID:ID="@+ID/fragmentimagesheader"    androID:name="com.adriagate.adriagateonlineandroID.fragments.Imagesheader"    tools:layout="@layout/fragment_images_header" androID:layout_wIDth="match_parent"    androID:layout_height="match_parent" ></fragment><fragment xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools" androID:ID="@+ID/fragmentimagesGrID"    androID:name="com.adriagate.adriagateonlineandroID.fragments.ImagesList"    tools:layout="@layout/fragment_images_List" androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content" ></fragment>   </relativeLayout>

请注意,此布局有一个名为fragmentimagesGrID的重要片段,它具有以下布局:

<FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent"androID:layout_height="match_parent"tools:context="com.adriagate.adriagateonlineandroID.fragments.ImagesList">    <androID.support.v7.Widget.RecyclerVIEw      androID:ID="@+ID/recycler_vIEw_images"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"     tools:Listitem="@layout/recycler_vIEw_images_one_row"    >
</FrameLayout>

这是我在Recycler视图中的一个元素的布局:

<?xml version="1.0" enCoding="utf-8"?>     <FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"       androID:orIEntation="vertical"       androID:layout_wIDth="wrap_content"       androID:layout_height="wrap_content"        xmlns:tools="http://schemas.androID.com/tools"      ><ImageVIEw    androID:ID="@+ID/imageVIEwImagesAllOneRow"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_gravity="center_horizontal"    tools:src="@drawable/slika_200_200"    />   </FrameLayout>

解决方法 看起来它发生是因为您的图像有不同的大小.
将项目更改为linearLayout并将其布局高度和宽度设置为match_parent.设置gravity =“center”(线性布局).
另一个问题是androID:layout_height =“wrap_content”.将height属性设置为wrap_content时,RecyclerVIEw无法正常工作.如果您仍想将RecyclerVIEw与wrap_content一起使用,则可以使用 this解决方案 总结

以上是内存溢出为你收集整理的在RecyclerView中的android – GridLayoutManager 3列全部内容,希望文章能够帮你解决在RecyclerView中的android – GridLayoutManager 3列所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1123686.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存