【发布时间】:2017-08-07 21:28:16
【问题描述】:
我使用recyclerview实现了gridview,问题是图像显示不正确,因为图像之间有太多空间,这里是mainactivity的xml和griditem.xml
mainactivity.xml
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_below="@+id/toolbar"
android:layout_width="match_parent"
android:scrollbars="vertical"
android:layout_height="match_parent"/>
</RelativeLayout>
griditem.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:id="@+id/iv"/>
</LinearLayout>
在主要活动中:
GridLayoutManager grid = new GridLayoutManager(this,2);
recyclerView.setAdapter(new MovieRecyclerAdapter());
recyclerView.setLayoutManager(grid);
您可以看到两列图像周围有空格,我该如何去除这些空格?
高度后包裹内容
【问题讨论】:
-
我什么都没做
-
图像视图和布局的高度和宽度都与父级匹配?
-
试试 recyclerView.setHasFixedSize(true);在设置适配器之前。
-
什么都没发生
-
如果有效,请将其作为答案发布
标签: java android xml gridview android-recyclerview