【发布时间】:2017-09-09 21:24:19
【问题描述】:
当我在适配器“onCreateViewHolder”中为卡充气时,由于“InflateException”,我从 Google Play 开发控制台收到了崩溃报告,但我似乎找不到问题的根源。这是来自开发控制台的堆栈跟踪:
这是导致崩溃的方法:
@Override
public HeatmapDataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//there was a crash report (InflateException) while inflating this view, but I can't seem to find the issue?
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_heatmap, parent, false);
HeatmapDataViewHolder heatmapDataViewHolder = new HeatmapDataViewHolder(listener, v);
return heatmapDataViewHolder;
}
我已阅读 here 的问题可能与 android:foreground="?android:attr/selectableItemBackground" 相关,但我找不到任何原因导致此问题。即使是问题,我将如何在卡片视图上获得涟漪效应?
这是我要膨胀的 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
card_view:cardCornerRadius="2dp"
android:background="@color/light_gray"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="3"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/card_image_view"
android:layout_gravity="center"
android:scaleType="centerCrop"
app:riv_corner_radius="2dp"
android:src="@drawable/test_bkg"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:background="@android:drawable/screen_background_dark_transparent"
android:orientation="vertical"
android:paddingLeft="14dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:id="@+id/title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="@color/white"
android:textStyle="bold"
android:text="Title"/>
<TextView
android:id="@+id/subtitle_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="@color/white"
android:textStyle="bold"
android:text="Sub Title"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ImageView
android:id="@+id/delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/icon_padding"
android:src="@drawable/ic_delete_black_24dp"
android:tint="@color/dark_gray"
android:background="?android:attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/icon_padding"
android:src="@drawable/ic_edit_black_24dp"
android:tint="@color/dark_gray"
android:background="?android:attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/icon_padding"
android:src="@drawable/ic_share_black_24dp"
android:tint="@color/dark_gray"
android:background="?android:attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/view_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/icon_padding"
android:src="@drawable/ic_view_24dp"
android:tint="@color/dark_gray"
android:background="?android:attr/selectableItemBackgroundBorderless" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
提前致谢。
【问题讨论】:
-
分享HomeAdapter类的代码
-
哦,是的,对不起,我想包括那个。我把它添加到帖子中
标签: android xml android-recyclerview adapter