CardView作为RecyclerView项目中的父项未显示涟漪效应

时间:2017-04-16 06:37:01

标签: android android-recyclerview android-cardview android-viewholder

我有一个RecyclerView,我正在填充项目,如下面的布局所述。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cv_item_display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:weightSum="9">
    .
    .
    .
    </LinearLayout>
</android.support.v7.widget.CardView>

每当在RecyclerView中点击cv_item_display引用的CardView时,当我将OnClickListener附加到卡上时,我会看到Card BUT上的涟漪效应,我不再受到涟漪效应。下面是我附加OnClickListener的ViewHolder的代码。

public class RosterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
    TextView tvStudentCount, tvRosterName;
    ImageView ivDelete, ivView;
    CardView cvItemDisplay;

    public RosterViewHolder(View itemView) {
        super(itemView);
        tvStudentCount = (TextView) itemView.findViewById(R.id.tv_question_student_count);
        tvRosterName = (TextView) itemView.findViewById(R.id.tv_questionnaire_roster_name);
        ivDelete = (ImageView) itemView.findViewById(R.id.iv_delete);
        ivView = (ImageView) itemView.findViewById(R.id.iv_view);
        cvItemDisplay = (CardView) itemView.findViewById(R.id.cv_item_display);
        cvItemDisplay.setOnClickListener(this);
        ivDelete.setOnClickListener(this);
        ivView.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        final int position = getAdapterPosition();
        switch (view.getId()) {
            case R.id.iv_delete:
               mRealm.executeTransaction(new Realm.Transaction() {
                   @Override
                   public void execute(Realm realm) {
                       mRealm.where(RosterEntry.class).equalTo("rosterId", mRealmResults.get(position).getId()).findAll().deleteAllFromRealm();
                       mRealmResults.deleteFromRealm(position);
                   }
               });
               break;

            case R.id.iv_view:
               Utils.startRosterItemsActivity(view.getContext(), mRealmResults.get(position).getName(), mRealmResults.get(position).getId(), false);
               break;

            case R.id.cv_item_display:
               startAttendanceActivity(mRealmResults.get(position).getId());
               break;
        }
    }
}

编辑:我还发现了一些奇怪的行为 - 横向模式显示波纹效果,但纵向模式没有。

0 个答案:

没有答案