扩展cardview类在卡片周围显示白色矩形

Moj*_*med 5 java android android-custom-view android-cardview

我正在扩展CardView类,因为我想为列表视图的每一行创建自定义视图。这是我的xml布局

<com.mojiapps.myquran.items.TranslationDownloadItemView  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?selectableItemBackground"
android:gravity="right"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3dp"
card_view:cardPreventCornerOverlap="false">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
...

</com.mojiapps.myquran.items.TranslationDownloadItemView>
Run Code Online (Sandbox Code Playgroud)

这是我的java类

public class TranslationDownloadItemView extends CardView {


public TranslationDownloadItemView(Context context) {
    super(context);
    init();
}

public TranslationDownloadItemView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

private void init() {
    LayoutInflater inflater = LayoutInflater.from(getContext());

    inflater.inflate(R.layout.translation_type_row, this);
...
}
...
}
Run Code Online (Sandbox Code Playgroud)

这就是结果

在此处输入图片说明

有谁能够帮助我?

Jav*_*ado 2

我遇到了将 CardView 背景设置为透明的问题。我解决了它设置非阿尔法颜色。

尝试将您的设置设置android:foreground为没有 alpha 的值。