【问题标题】:cardview size not decreasing in my recycler view in my app在我的应用程序的回收站视图中,cardview 大小没有减少
【发布时间】:2015-12-26 19:07:09
【问题描述】:

我对 Android 很陌生。我正在尝试调整我的 cardview 的大小,但它没有效果并恢复到以前的大小。谁能帮帮我?

这是我的cardviewRecyclerview 代码。

回收站视图

<?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>

卡片视图布局

<?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>

【问题讨论】:

    标签: android android-recyclerview android-cardview


    【解决方案1】:

    如果你想调整完整 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 中的填充 - 占用一些空间。

    如果有更多问题,欢迎提问

    【讨论】:

    • 我想显示我的卡片项目左右两边没有空格@piotrek1543
    • 你注意到 recyclerView 中的填充了吗?删除它们以获得完整的宽度和高度
    • 我都删除了,但我再次在左侧和右侧获得空间@piotrek1543
    猜你喜欢
    • 1970-01-01
    • 2021-09-24
    • 2023-03-26
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    相关资源
    最近更新 更多