【发布时间】:2018-01-13 04:27:02
【问题描述】:
在单独的应用程序中进行测试时,CardView 高程可以正常工作,但是当 cardView 的相同代码用于制作 RecyclerView 的项目时,高程不再出现。
这里是 RecyclerView 列表项的代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
card_view:cardUseCompatPadding="true"
app:cardMaxElevation="6dp"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="24dp">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="250dp" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/thumbnail"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
这是我的主要活动 xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bitmap"
android:layerType="software"
android:padding="10dp"
tools:context="com.example.android.vikramadityastimeline.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/card_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
/>
</FrameLayout>
【问题讨论】:
-
现在是什么样子的?可以分享截图吗?
-
你应该为 FrameLayout 设置填充...
-
试过..没用
-
我正面临与此相关的问题。如果我在
onBindViewHolder()中更改cardView 的背景,它的阴影不会显示。 -
将此添加到您的 xml 中的 CardView。应用程序:cardElevation="2dp"。将 2dp 更改为您想要的任何值。
标签: android android-recyclerview android-cardview android-elevation