网格中的 CardView 不在所有侧面显示阴影
CardView in Grid not displaying shadow on all sides
我最近放弃了向 GridView
项添加阴影的想法并实施了 CardViews
。
我面临的问题如下:CardView
项目在 GridView
的边界处没有显示阴影,如下图所示:
Android Studio 中的 CardView
预览显示四面都有边框的布局,如 this picture.
所示
如何在 GridView 的边上添加阴影?为什么 Cardview
项没有阴影?
我尝试 reducing/increasing GridView 列的大小,我尝试将 margin
和 padding
添加到 GridView
。我尝试为 Cardview
添加更大的边距。 None 他们工作了。
这是 GridView
的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<GridView
android:id="@+id/CatalogGridList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="8dp"
android:numColumns="auto_fit"
android:columnWidth="128dp"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"/>
</LinearLayout>
This 是 CardView 布局的要点 xml。
正如@Ameer 所说,您需要在包含的 GridView
上添加一些填充,以便允许 space 用于阴影。根据需要调整填充属性(左和右):
<GridView
android:id="@+id/CatalogGridList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="8dp"
android:numColumns="auto_fit"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:columnWidth="128dp"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"/>
诀窍是将 android:clipToPadding
属性与水平填充一起使用。将这些属性添加到您的 GridView
标签:
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:clipToPadding="false"
如果不设置 clipToPadding="false"
,您会看到您提到的白条,但有了它,您会看到:
我最近放弃了向 GridView
项添加阴影的想法并实施了 CardViews
。
我面临的问题如下:CardView
项目在 GridView
的边界处没有显示阴影,如下图所示:
Android Studio 中的 CardView
预览显示四面都有边框的布局,如 this picture.
如何在 GridView 的边上添加阴影?为什么 Cardview
项没有阴影?
我尝试 reducing/increasing GridView 列的大小,我尝试将 margin
和 padding
添加到 GridView
。我尝试为 Cardview
添加更大的边距。 None 他们工作了。
这是 GridView
的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<GridView
android:id="@+id/CatalogGridList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="8dp"
android:numColumns="auto_fit"
android:columnWidth="128dp"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"/>
</LinearLayout>
This 是 CardView 布局的要点 xml。
正如@Ameer 所说,您需要在包含的 GridView
上添加一些填充,以便允许 space 用于阴影。根据需要调整填充属性(左和右):
<GridView
android:id="@+id/CatalogGridList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="8dp"
android:numColumns="auto_fit"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:columnWidth="128dp"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"/>
诀窍是将 android:clipToPadding
属性与水平填充一起使用。将这些属性添加到您的 GridView
标签:
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:clipToPadding="false"
如果不设置 clipToPadding="false"
,您会看到您提到的白条,但有了它,您会看到: