CardView 之间的 space 过多
Too much space in between CardViews
我的卡片视图一直存在问题,其中 android 工作室在它们之间放置了太多 space。 Here is an example screenshot 我是从模拟器上拿的。对于我的布局 inflater,这是我使用的代码:
@Override
public DriveStatsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
{
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview_layout, viewGroup, false);
DriveStatsViewHolder dsvh = new DriveStatsViewHolder(v);
return dsvh;
}
下面是我的cardview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<TextView
android:id="@+id/FinishTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Drive_Date"
android:layout_toStartOf="@+id/Total_Drive_Time"
android:textAlignment="textEnd"
android:textSize="18sp"
tools:text="Finish Time"/>
<TextView
android:id="@+id/Total_Drive_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:textAlignment="viewStart"
android:textSize="18sp"
tools:text="Total Drive Time"/>
<TextView
android:id="@+id/Drive_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textSize="24sp"
tools:text="Default Text"/>
<TextView
android:id="@+id/Start_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Drive_Date"
android:textSize="18sp"
tools:text="Start Time"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
我是 android 工作室的新手,如有任何帮助,我们将不胜感激。
您的外部 RelativeLayout
的高度是 match_parent
,因此列表中的每个项目都与您的屏幕一样高。然而,CardView
本身只有 wrap_content
的高度,所以大部分 space 将被留空。
我的卡片视图一直存在问题,其中 android 工作室在它们之间放置了太多 space。 Here is an example screenshot 我是从模拟器上拿的。对于我的布局 inflater,这是我使用的代码:
@Override
public DriveStatsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
{
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview_layout, viewGroup, false);
DriveStatsViewHolder dsvh = new DriveStatsViewHolder(v);
return dsvh;
}
下面是我的cardview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<TextView
android:id="@+id/FinishTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Drive_Date"
android:layout_toStartOf="@+id/Total_Drive_Time"
android:textAlignment="textEnd"
android:textSize="18sp"
tools:text="Finish Time"/>
<TextView
android:id="@+id/Total_Drive_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:textAlignment="viewStart"
android:textSize="18sp"
tools:text="Total Drive Time"/>
<TextView
android:id="@+id/Drive_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textSize="24sp"
tools:text="Default Text"/>
<TextView
android:id="@+id/Start_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Drive_Date"
android:textSize="18sp"
tools:text="Start Time"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
我是 android 工作室的新手,如有任何帮助,我们将不胜感激。
您的外部 RelativeLayout
的高度是 match_parent
,因此列表中的每个项目都与您的屏幕一样高。然而,CardView
本身只有 wrap_content
的高度,所以大部分 space 将被留空。