0
我一直在我的卡片视图中遇到问题,android studio在它们之间放置太多空间。 Here is an example screenshot我从模拟器中拿走了。因为在这里我的布局吹气是我使用的代码:CardViews之间的空间太大
@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工作室所以任何帮助,将不胜感激。
对不起,我应该指定上面的xml是cardview_layout.xml –
只需删除外部的RelativeLayout。或者,只要使RelativeLayout'wrap_content'的高度为 –
@DanielNugent我认为是一样的:),但'android:layout_height =“wrap_content”' –