我的应用程序中的回收站视图中的cardview大小没有减少

时间:2015-12-25 11:46:18

标签: android android-recyclerview android-cardview

我是Android新手。我正在尝试调整cardview的大小,但它没有效果并恢复到之前的大小。任何人都可以帮助我吗?

这是我的cardviewRecyclerview代码。

Recyclerview

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="1dp"
    android:paddingBottom="3dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/fragment_primary" tools:context=".Primary">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:paddingBottom="3dp"
        android:paddingLeft="3dp"
        android:paddingRight="3dp"
        android:paddingTop="2dp" />
</RelativeLayout>

cardview布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="360dp"
    android:layout_margin="8dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/row_image"
            android:layout_width="fill_parent"
            android:layout_height="250dp"
            android:layout_alignParentTop="true"
            android:scaleType="centerCrop"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
        <TextView
            android:id="@+id/row_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/row_image"
            android:maxLines="3"
            android:padding="8dp"
            android:textColor="#222"
            android:textStyle="bold"
            android:textSize="22dp" />
        <TextView
            android:id="@+id/row_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/row_title"
            android:maxLines="3"
            android:padding="8dp"
            android:textColor="#666"
            android:textSize="14dp" />
    </RelativeLayout>
</android.support.v7.widget.CardView>

1 个答案:

答案 0 :(得分:0)

如果您想调整整个CardView的大小,我认为您需要更改这些内容:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

如今,您只更改了图像的高度:

    android:layout_height="250dp"

另请阅读:What's the difference between fill_parent and wrap_content?

编辑:删除RecyclerView中的填充 - 占用一些空间。

如果有更多问题,请随意提问