Android: ListView 中 CardView 元素之间的间隙
Android: Gap between CardView elements in ListView
我似乎无法增加 ListView 中 CardView 元素之间的间距。我尝试将 android:layout_marginBottom="16dp"
添加到 CardView,但这没有任何作用。我正在使用 SDK 23。知道我能做什么吗?
卡片布局如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" <!-- Not Working -->
card_view:cardCornerRadius="@dimen/cardview_default_radius"
card_view:cardElevation="@dimen/cardview_default_elevation"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/abc_action_bar_content_inset_material">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout_dato"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/tip_detail_date"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_tip_dato"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
像这样更改您的列表视图
<ListView
android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/redBackground"
android:dividerHeight="1dip">// Increase this height as your need
</ListView>
对于Api23.你需要设置
app:cardUseCompatPadding="true"
在您的名片视图中
这样做:
<androidx.cardview.widget.CardView
android:id="@+id/matrix"
app:cardBackgroundColor="#f6f6f6"
app:cardCornerRadius="8dp"
app:cardElevation="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="0.7dp"
android:layout_marginTop="0.7dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
如果增加 cardElevation 或 marginBottom 间隙将会增加。
我似乎无法增加 ListView 中 CardView 元素之间的间距。我尝试将 android:layout_marginBottom="16dp"
添加到 CardView,但这没有任何作用。我正在使用 SDK 23。知道我能做什么吗?
卡片布局如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" <!-- Not Working -->
card_view:cardCornerRadius="@dimen/cardview_default_radius"
card_view:cardElevation="@dimen/cardview_default_elevation"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/abc_action_bar_content_inset_material">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout_dato"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/tip_detail_date"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_tip_dato"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
像这样更改您的列表视图
<ListView
android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/redBackground"
android:dividerHeight="1dip">// Increase this height as your need
</ListView>
对于Api23.你需要设置
app:cardUseCompatPadding="true"
在您的名片视图中
这样做:
<androidx.cardview.widget.CardView
android:id="@+id/matrix"
app:cardBackgroundColor="#f6f6f6"
app:cardCornerRadius="8dp"
app:cardElevation="2dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="0.7dp"
android:layout_marginTop="0.7dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
如果增加 cardElevation 或 marginBottom 间隙将会增加。