我在list_item.xml
“ RecyclerView的xml post cell”中使用CardView布局,我试图使卡片突出,并且分隔线的颜色像这样
但是看起来好像没有出现或没有颜色,
此图片适合当前情况
此 post_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
android:elevation="6dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/postTitle"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:ellipsize="end"
android:maxLines="2"
android:text="This is the post title,
you can check bla bla bla bla bla lkjdflkjhnfldkjhnflkjhnlfkjnglkjnlkjkln" />
<TextView
android:id="@+id/postDescription"
style="@style/Base.TextAppearance.AppCompat.Body2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:ellipsize="end"
android:maxLines="4"
android:text="This is the post titldfkjfdjffkjdhfnkjdsfjnkdsjnksskskjfnksjfnksjfnksjfnkjdfbdnfbjvb jkxzbvkjxcvbvkjve,
you can check bla bla bla bla bla lkjdflkjhnfldkjhnflkjhnlfkjnglkjnlkjkln" />
</LinearLayout>
<ImageView
android:id="@+id/postImage"
android:layout_width="match_parent"
android:layout_height="125dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_weight="3"
android:adjustViewBounds="true"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</android.support.v7.widget.CardView>
我试图通过在answer这样的RecyclerView上添加这两行来解决该问题,但是它不起作用
android:divider="#E6E6E6"
android:dividerHeight="0px"
答案 0 :(得分:1)
如果问题仍然存在,请在RecycleView中使用背景色。
答案 1 :(得分:0)
经过一番搜索,我发现这个question与同一问题有关
问题,因为此选项在清单文件中为假
three_df = pd.concat([df,df,df])
此answer还包含一些对我很有帮助的选择,例如
<application android:hardwareAccelerated="true" ...>
答案 2 :(得分:0)
尝试以下代码:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
app:cardUseCompatPadding="true"
app:cardElevation="6dp"
app:cardCornerRadius="3dp"
>
您必须使用:
app:cardElevation="6dp"
代替:
android:elevation="6dp"
要绘制阴影,必须使用hardwareAccelerated绘图
<application android:hardwareAccelerated="true" ...>
Android文档的解释:
CardView添加了额外的填充以在平台上绘制阴影,然后
这可能导致卡在L和L之前的大小不同。 如果需要将CardView与其他视图对齐,则可能需要api 版本特定的维度资源以说明更改。作为一个 或者,您可以将cardUseCompatPadding标志设置为true, CardView会在L平台及之后的平台上添加相同的填充值。
由于将cardUseCompatPadding标志设置为true会增加不必要的间隔 在用户界面中,默认值为false。
答案 3 :(得分:0)
设置此选项后
app:cardUseCompatPadding="true"
app:cardElevation="6dp"
我建议将白色添加为RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F5F5F5" // >>> this the color you need
>
</androidx.recyclerview.widget.RecyclerView>