【问题标题】:Recyclerview item row background color issuesRecyclerview 项目行背景颜色问题
【发布时间】:2017-06-22 13:47:11
【问题描述】:

我正在使用 recyclerview 列出 sql 中的项目,项目行的背景颜色有问题...我尝试更改它,但没有任何反应。

这是我的行布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="@color/bg_main"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout
        android:padding="10dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/default_avatar"/>

        <RelativeLayout
            android:padding="10dip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <TextView
                android:textSize="18sp"
                android:textColor="@color/text_color_black"
                android:id="@+id/opponentsName"
                android:text="Roger Nkosi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:layout_marginTop="5dp"
                android:textSize="14sp"
                android:textColor="@color/brownish_gray"
                android:id="@+id/callStatus"
                android:text="Roger Nkosi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            </LinearLayout>

            <TextView
                android:id="@+id/dateCallMade"
                android:layout_alignParentRight="true"
                android:text="14:00"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </RelativeLayout>

    </LinearLayout>
    </android.support.v7.widget.CardView>

</LinearLayout>

这是我的片段布局

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_main"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".view.fragments.PrivateVoiceCallsDialogFragment">


   <!-- A RecyclerView with some commonly used attributes -->
   <android.support.v7.widget.RecyclerView
       android:scrollbars="vertical"
       android:id="@+id/voice_recycler_view"
       android:layout_height="match_parent"
       android:layout_width="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

*bg_main 是一种简单的白色,有或没有它,行项目是暗的......

【问题讨论】:

  • 尝试使用这个应用程序:cardBackgroundColor="@color/colorPrimary"
  • 谢谢,我用过,效果很好,非常感谢。

标签: android android-recyclerview recyclerview-layout


【解决方案1】:

我认为 CardView 与您的父 linearLayout 重叠,因此您看不到颜色。在 CardView 上使用 cardBackgroundColor 属性或更改其子 linearLayout 的背景颜色

【讨论】:

    【解决方案2】:

    在您的 cardView 组件中使用 cardBackgroundColor 属性,它会做想要的事情。

    【讨论】:

      猜你喜欢
      • 2023-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多