【发布时间】:2018-02-07 06:52:15
【问题描述】:
我最近放弃了为GridView 项目添加阴影的想法并实现了CardViews。
我面临的问题如下:CardView 项目在GridView 的边界处没有显示阴影,如下图所示:
Android Studio 中的CardView Preview 显示了四边都有边框的布局,如this picture 所示。
如何在 GridView 的侧面也添加阴影?为什么Cardview 项目没有影子?
我尝试减少/增加 GridView 列的大小,我尝试将 margin 和 padding 添加到 GridView。我尝试为Cardview 添加更大的边距。他们都没有工作。
这是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 的要点。
【问题讨论】:
-
在 GridView 标签中尝试 android:padding="" 属性
-
@AmeerHamza 正如我在帖子中所说,添加填充会增加 GridView 边距上的空白。没有来自
CardView的阴影 -
尝试转换 android:layout_width="match_parent" 这个 wrap_contant 然后使用 padding
-
@AmeerHamza 我恐怕也不能解决它。
标签: android gridview android-cardview cardview