RecyclerView 的透明背景

inn*_*dia 2 android android-recyclerview

这是我的回收视图中聊天窗口的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:orientation="vertical"
android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="10dp" />
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="418"
                android:layout_width="0dp"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:orientation="horizontal"
                        android:layout_height="wrap_content">
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="100"
                            android:gravity="right"
                            android:layout_height="match_parent">
                            <ImageButton
                                android:id="@+id/btn_profilepic_recview_chats"
                                android:background="@drawable/ripple"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />
                        </LinearLayout>
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="323"
                            android:layout_height="match_parent" />
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:orientation="horizontal"
                        android:layout_height="wrap_content">
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="100"
                            android:layout_height="wrap_content" />
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="323"
                            android:orientation="vertical"
                            android:layout_height="wrap_content">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                                <ImageView
                                    android:src="@drawable/chat_img_bubbletop"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content" />
                            </LinearLayout>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:background="#afebff">
                                <TextView
                                    android:paddingLeft="8dp"
                                    android:paddingRight="8dp"
                                    android:textColor="#000000"
                                    android:textSize="17sp"
                                    android:id="@+id/txt_chatmessage_recview_chats"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content" />
                            </LinearLayout>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                                <ImageView
                                    android:src="@drawable/chat_img_bubbletop"
                                    android:rotation="180"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content" />
                            </LinearLayout>
                        </LinearLayout>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:orientation="horizontal"
                        android:layout_height="wrap_content">
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="100"
                            android:layout_height="match_parent" />
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_weight="323"
                            android:layout_height="match_parent">
                            <TextView
                                android:text="12.02.2012"
                                android:id="@+id/txt_date_recview_chats"
                                android:textSize="12sp"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />
                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_weight="216"
                android:layout_width="0dp"
                android:layout_height="wrap_content" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="10dp" />
    </LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

recyclerview 的背景是一个简单的图像,应该通过线性布局显示。但不幸的是,结果是这样的:

在此输入图像描述

因此,正如您所看到的,背景显示得恰到好处,但我在这里使用的卡片视图的透明布局是一些有线黑色。

我可以把它做成任何我想要的颜色,但是:

android:background="@android:color/transparent"
Run Code Online (Sandbox Code Playgroud)

它只是变黑了。

有人能帮我一下吗?

感谢您!:)

小智 8

您可以使用

app:cardBackgroundColor="@android:color/transparent"
Run Code Online (Sandbox Code Playgroud)


May*_*tel 5

您必须更改 CardView 背景颜色。您可以使用

app:cardBackgroundColor="@android:color/transparent"
Run Code Online (Sandbox Code Playgroud)

代替

android:background="@android:color/transparent"
Run Code Online (Sandbox Code Playgroud)

喜欢 :

    <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"
        app:cardBackgroundColor="@android:color/transparent">

        <!-- Your view design -->

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)