java RecyclerView和gridView
我使用recyclerview实现了gridview。问题是图像没有正确显示,就像图像之间有太多空间一样,这里是mainactivity和griditem的xml。xml
主要活动。xml
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<安卓.support.v7.widget.Toolbar
安卓:id="@+id/toolbar"
安卓:layout_width="match_parent"
安卓:layout_height="?attr/actionBarSize"
安卓:background="?attr/colorPrimary"
安卓:elevation="4dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<安卓.support.v7.widget.RecyclerView
安卓:id="@+id/rv"
安卓:layout_below="@+id/toolbar"
安卓:layout_width="match_parent"
安卓:scrollbars="vertical"
安卓:layout_height="match_parent"/>
</RelativeLayout>
griditem。xml:
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content">
<ImageView
安卓:layout_width="200dp"
安卓:layout_height="200dp"
安卓:layout_gravity="center"
安卓:id="@+id/iv"/>
</LinearLayout>
在主要活动中:
GridLayoutManager grid = new GridLayoutManager(this,2);
recyclerView.setAdapter(new MovieRecyclerAdapter());
recyclerView.setLayoutManager(grid);
您可以看到图像的两列周围有空格,如何删除这些空格
包装内容的高度之后
# 1 楼答案
这样做:
项目xml外部布局的高度也应为
wrap_content
# 2 楼答案
girditem。xml
要在项目之间添加空格,请将边距设置为所需的dp数