所以我正在学习Android的应用程序开发,我有点卡住了。我正在尝试使用CardView制作RecyclerView,但是CardView之间的空间太大了。这就是它的样子。
我将追求Google应用程序与提要的更多外观。 这更像是我拍摄的目的。
无论如何,我已经在这个网站上搜索并搜索了我的问题的解决方案,但似乎没有什么对我有用。我希望有人能给我一些真正有效的东西。
这是我的卡片视图的 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="10dp">
<android.support.v7.widget.CardView
android:id="@+id/cv"
android:layout_width="match_parent"
android:layout_height="120dp"
app:cardCornerRadius="10dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/note_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_below="@+id/event_time"
android:textSize="24sp" />
<TextView
android:id="@+id/note_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/note_title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
顶部和底部空间是由填充引起的android:paddingBottom="10dp",删除它或减少它
减少根约束布局的 PadingBotom 您可以放置 3 或 4 DP 而不是 10dP。
android:paddingBottom="10dp"
我也不知道你的代码副本是否不好......约束布局必须在末尾关闭:在此之后:
</android.support.v7.widget.CardView>
你必须有这个:
</android.support.constraint.ConstraintLayout>
来自CardView
的文档:
在棒棒糖之前,
CardView
在其内容中添加填充并为该区域绘制阴影。如果你想CardView
在棒棒糖平台上添加内部填充,你可以调用setUseCompatPadding(boolean)
并传递true
。
在布局中,CardView
标签上有此属性:
app:cardUseCompatPadding="true"
这与上面引用的方法相同。
因此,即使您的卡片所有边的边距为零,由于内部填充行为,用户仍会看到它们之间的空间。如果你想要非常紧凑的间距,你必须删除此属性(当然,你仍然会得到棒棒糖之前的更大间距(。