android - RecyclerView 的透明背景

标签 android android-recyclerview

这是我在 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>

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

enter image description here

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

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

android:background="@android:color/transparent"

它只是变黑了。

有人可以帮我吗?

谢谢! :)

最佳答案

你可以使用

app:cardBackgroundColor="@android:color/transparent"

关于android - RecyclerView 的透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50873643/

相关文章:

android - OpenGL ES 顶点/索引

java - 将本地数据与 Firebase 数据库合并并在 recyclerview 中显示

android - RecyclerView 根本不更新

android - 如何使用 RabbitMQ 在两个 Android 应用程序之间发送消息

android - 将 Spring for android 依赖项添加到 gradle + Android studio 项目

java - 取消选中所有复选框后禁用按钮

java - 如何使用偏移 Recycler View 进行自动平滑滚动?

android - RecyclerView 的 GridLayoutManager 上的方形布局

android - 按字母顺序(来自数据库)使用光标中的内容对 ListView 进行排序

android - 使用 GIF 和 Glide 库创建动画启动