[英]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.