簡體   English   中英

如何刪除cardview中不必要的頂部填充?

[英]How can i remove unnecessary top padding in cardview?

我設法在我的應用程序中實現了 Cardviews,但是 cardview 在頂部顯示了一個不必要的填充。

在此處輸入圖片說明

我想要實現的是獲得這樣的標題圖像:

在此處輸入圖片說明

這是我的 cardview 布局文件:

<android.support.v7.widget.CardView
android:id="@+id/programCardview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardUseCompatPadding="true"
xmlns:card_view="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/programHeader"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:src="@drawable/createdprogramviewcard"/>

    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:paddingBottom="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp">

        <TextView
            android:id="@+id/programTitle"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="Programme d'endurance"
            android:textSize="20sp"
            android:textAlignment="center"/>

        <TextView
            android:id="@+id/objectif"
            android:layout_below="@+id/programTitle"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Objectif : " />

        <TextView
            android:id="@+id/programObjectif"
            android:layout_below="@+id/programTitle"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="6 séances"
            android:layout_toRightOf="@id/objectif"/>

        <TextView
            android:id="@+id/programWorkouts"
            android:layout_below="@+id/programTitle"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textAlignment="textEnd"
            android:layout_alignParentRight="true"
            android:text="6 séances" />


    </RelativeLayout>

</LinearLayout>

這是 RecyclerView 的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 

android:layout_height="match_parent" android:padding="16dp">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerViewPrograms"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v7.widget.RecyclerView>

我設法更改了屬性 cardUseCompatPadding 但這不會影響 cardview 的內部形式,它只是將它們分開。

提前致謝。

我通過將 imageView 的高度更改為 130dp 找到了解決我的問題的方法。 顯然,由於我將圖像的 with 與 match_parent 進行了匹配,因此我必須在 cardview 中找到適合圖像的確切高度,而不會給它一些額外的填充。

這種情況有兩個原因,第一個是CardView的 height 屬性在match_parent或者比組件占用的尺寸更大,同時布局的gravity屬性在center

要修復它,只需將 LinearLayout 的重力設置為 center | 填充或只是填充。

暫無
暫無

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

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