CardView显示白色居中布局

我在回收站视图中将卡片视图用作行项目,并且每个卡片视图都有不同的背景颜色。 我已成功完成此操作,直到在cardview中添加角半径。现在它在中间显示一些白色布局。

这是我的cardView的代码。

    <androidx.cardview.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:id="@+id/cvNB"
    app:cardCornerRadius="10dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_margin="10dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/txtNBHead"
                android:layout_weight="0.9"
                android:textSize="24sp"
                android:fontFamily="@font/raleway_semibold"
                android:textColor="@color/colorPrimary"/>
            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:id="@+id/NBOptions"
                android:src="@drawable/ic_menu_icon_white_24dp"
                android:layout_weight="0.1"/>
        </LinearLayout>
        <TextView
            android:id="@+id/txtNBStory1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/raleway_thin"
            android:textSize="18sp"
            android:textColor="@color/colorPrimary"
            android:layout_margin="2dp"/>
        <TextView
            android:id="@+id/txtNBStory2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/raleway_thin"
            android:textSize="18sp"
            android:textColor="@color/colorPrimary"
            android:layout_margin="2dp"/>
        <TextView
            android:id="@+id/txtNBStory3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/raleway_thin"
            android:textSize="18sp"
            android:textColor="@color/colorPrimary"
            android:layout_margin="2dp"/>
    </LinearLayout>
</androidx.cardview.widget.CardView>

我在回收站视图中使用它,具有以下代码所示的不同背景颜色

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLlipoP){
        holder.cvNB.getBackground().setalpha(0);
    } else {
        holder.cvNB.setCardBackgroundColor(ContextCompat.getcolor(context,colors[index]));
    }

这就是我要得到的 Cardview displaying white section

我真的很沮丧,请帮帮我

这是回收站视图布局的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/listMain"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:scrollbars="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"/>
    </ScrollView>

    <com.google.android.material.floatingactionbutton.FloatingactionButton
        android:id="@+id/fabAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:src="@drawable/icon_add"
        app:backgroundTint="@color/colorProfileText"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.airbnb.lottie.LottieAnimationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/listNBAnim"
    app:lottie_fileName="nb_loading_anim.json"
    app:lottie_loop="true"
    android:visibility="gone"
    app:lottie_autoPlay="true"/>
</RelativeLayout>
asfhd1989 回答:CardView显示白色居中布局

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3100317.html

大家都在问