gpt4 book ai didi

java - 如何删除 cardview 中不必要的顶部填充?

转载 作者:行者123 更新时间:2023-12-04 18:00:49 24 4
gpt4 key购买 nike

我设法在我的应用中实现了 Cardview,但 Cardview 在顶部显示了不必要的填充。

enter image description here

我想要实现的是获得这样的标题图片:

enter image description here

这是我的卡片 View 布局文件:

<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 找到了解决我的问题的方法。显然,因为我将图像与 match_parent 匹配,所以我必须找到适合 cardview 内图像的确切高度,而不需要给它一些额外的填充。

关于java - 如何删除 cardview 中不必要的顶部填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35653380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com