Android 卡片视图布局和分隔器颜色的显著性
我在“xml post cell”中为RecyclerView使用了CardView布局,我试图使卡片突出,分隔符的颜色接近灰色,如下所示Android 卡片视图布局和分隔器颜色的显著性,android,android-layout,android-recyclerview,android-xml,android-cardview,Android,Android Layout,Android Recyclerview,Android Xml,Android Cardview,我在“xml post cell”中为RecyclerView使用了CardView布局,我试图使卡片突出,分隔符的颜色接近灰色,如下所示 但它似乎没有出现,也没有颜色, 这张照片是针对当前情况拍摄的 此post_item.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk
但它似乎没有出现,也没有颜色,
这张照片是针对当前情况拍摄的 此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>
但它不起作用
android:divider=“#e6”
android:dividerHeight=“0px”
在做了一些搜索之后,我发现这是关于同一个问题的
此问题是因为此选项在清单文件中为false
在做了一些搜索之后,我发现了关于同一问题的信息
此问题是因为此选项在清单文件中为false
请尝试以下代码:
<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"
>
而不是:
android:elevation="6dp"
要绘制阴影,必须使用硬件加速绘制
<application android:hardwareAccelerated="true" ...>
Android文档的解释:
CardView添加了额外的填充,以便在之前在平台上绘制阴影
L
这可能导致卡在L和L之前的大小不同。
如果需要将CardView与其他视图对齐,则可能需要api
用于说明更改的特定于版本的维度资源。作为
或者,您可以将CardUseCompatingFlag设置为true和
CardView将在平台L和之后添加相同的填充值
因为将CardUseCompatingFlag设置为true会增加不必要的间隙
在UI中,默认值为false
请尝试以下代码:
<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"
>
而不是:
android:elevation="6dp"
要绘制阴影,必须使用硬件加速绘制
<application android:hardwareAccelerated="true" ...>
Android文档的解释:
CardView添加了额外的填充,以便在之前在平台上绘制阴影
L
这可能导致卡在L和L之前的大小不同。
如果需要将CardView与其他视图对齐,则可能需要api
用于说明更改的特定于版本的维度资源。作为
或者,您可以将CardUseCompatingFlag设置为true和
CardView将在平台L和之后添加相同的填充值
因为将CardUseCompatingFlag设置为true会增加不必要的间隙
在UI中,默认值为false
如果问题仍然存在,请在RecycleView中使用背景色。如果问题仍然存在,请在RecycleView中使用背景色。设置此选项后
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>
>这是您需要的颜色
>
设置此选项后
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>
>这是您需要的颜色
>
精彩答案!这正是我需要的精彩答案!这正是我需要的