删除RecyclerView android中项目之间的间距
我正在使用RecyclerView显示项目列表,需要删除项目之间的默认间距。我正在尝试在我的LinearLayoutManager上设置RecyclerView.LayoutParams并将边距设置为零,但没有成功 这是我的密码: layout/fragment\u recycler.xml删除RecyclerView android中项目之间的间距,android,material-design,android-recyclerview,android-cardview,Android,Material Design,Android Recyclerview,Android Cardview,我正在使用RecyclerView显示项目列表,需要删除项目之间的默认间距。我正在尝试在我的LinearLayoutManager上设置RecyclerView.LayoutParams并将边距设置为零,但没有成功 这是我的密码: layout/fragment\u recycler.xml <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/freshSwipeView" an
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/freshSwipeView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/freshRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<mypackagename.ui.view.RecyclingImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/img_no_avatar" />
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:padding="@dimen/spacing"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:textSize="@dimen/text_smallest" />
</LinearLayout>
</android.support.v7.widget.CardView>
我需要帮助…只需删除您的布局/cardwiew\u recycler.xml中的cardwiew,android就会设置您不想要的间距
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<mypackagename.ui.view.RecyclingImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/img_no_avatar" />
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:padding="@dimen/spacing"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:textSize="@dimen/text_smallest" />
</LinearLayout>
其他一切保持原样给android:layout\u height=包装内容,而不是将父项与项目根布局匹配
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
-------
-------
</android.support.v7.widget.CardView>
-------
-------
尝试使用cardElevation=0dp。这将消除recyclerview项目之间的额外间距
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:layout_marginEnd="2dp"
app:cardElevation="0dp">
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<mypackagename.ui.view.RecyclingImageView
android:id="@+id/avatar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/img_no_avatar" />
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:ellipsize="end"
android:padding="@dimen/spacing"
android:textColor="@color/black"
android:layout_alignParentBottom="true"
android:textSize="@dimen/text_smallest" />
</LinearLayout>
<android.support.v7.widget.CardView />
删除行
设置可视性(消失)
删除后,它可以完美地工作。在我下面的例子中,代码工作正常
<android.support.v7.widget.RecyclerView
android:id="@+id/freshRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />
是否无法调整卡片视图放置的间距?我想保留间距,但我不想要像20dp这样的间距?为什么cardview会添加间距?为什么在代码中定义但从不使用参数?
<android.support.v7.widget.RecyclerView
android:id="@+id/freshRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />