Android recyclerview中cardview顶部和底部的不必要填充物
我在recyclerview中有一个cardview,我面临的问题是,在填充recyclerview时,cardview中imageview的顶部和底部会出现不必要的填充。recyclerview行的代码如下所示。请帮助我 我在堆栈上尝试了很多代码,但没有用Android recyclerview中cardview顶部和底部的不必要填充物,android,android-recyclerview,android-cardview,Android,Android Recyclerview,Android Cardview,我在recyclerview中有一个cardview,我面临的问题是,在填充recyclerview时,cardview中imageview的顶部和底部会出现不必要的填充。recyclerview行的代码如下所示。请帮助我 我在堆栈上尝试了很多代码,但没有用 <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_margin="5dp"
card_view:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/productsearch_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/productsearch"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Proin Volutpat Purus."
android:textSize="11sp"
android:scaleY="1.2"
android:layout_weight="2"
android:layout_gravity="center"
android:textColor="@android:color/black"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="$"
android:layout_gravity="center"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:textColor="@color/textcolorpink"/>
<TextView
android:id="@+id/prodprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:text="25"
android:textColor="@color/textcolorpink"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
尝试添加
android:adjustViewBounds=“true”
转到ImageView
<ImageView
android:id="@+id/productsearch_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/productsearch"/>
另外,为什么要对ImageView使用LinearLayout,您可以将其删除。这是一个不必要的嵌套尝试添加
android:adjustViewBounds=“true”
转到ImageView
<ImageView
android:id="@+id/productsearch_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/productsearch"/>
另外,为什么要对ImageView使用LinearLayout,您可以将其删除。这是不必要的筑巢