首页 > 解决方案 > Android cardview 第一项和最后一项未正确显示

问题描述

Cardview 第一项

所以我按照 ude*y 的 Android 教程进行操作,一切正常,唯一的问题是 cardview 的第一项和最后一项没有正确显示。

标签: androidandroid-layoutkotlinandroid-cardview

解决方案


我认为您必须根据需要设置边距或填充。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp"
        tools:context=".MainActivity">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" />
        <TextView
            android:id="@+id/empty_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/tryagain"
            android:gravity="center"
            android:visibility="gone"
            android:text="@string/no_data_available" />
    </RelativeLayout>

</LinearLayout>

您想查看更多完整的卡片视图示例,请关注此 github:

https://github.com/dharmakshetri/CardViewExample/blob/master/app/src/main/res/layout/main.xml

和完整的源代码: CardViewExample


推荐阅读