我正在扩展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>
这是我的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);
...
}
...
}
这是结果
任何人都可以帮助我吗?
答案 0 :(得分:0)
我遇到了这个问题,将CardView背景设置为透明的。我解决了它设置非alpha颜色。
尝试将android:foreground
设置为不带alpha的内容。
答案 1 :(得分:0)
对于我来说,我将白色背景设置为CardView
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@color/white">
或者您可以将cardElevation设置为0dp,但这会禁用阴影
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/trans_black_darker"
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:cardElevation="0dp">