簡體   English   中英

CardViews之間的空間太大

[英]Too much space in between CardViews

我的卡片視圖一直存在問題,其中android studio在它們之間放置了太多空間。 這是我從模擬器中截取的示例屏幕截圖 對於我的布局充氣機,這是我使用的代碼:

@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 studio的新手,所以我們將不勝感激。

您外部的RelativeLayout的高度為match_parent ,因此列表中的每個項目都與屏幕一樣高。 但是, CardView本身僅具有wrap_content的高度,因此大部分空間將留為空白。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM