通知RecyclerView时无边界RippleDrawable问题

时间:2017-09-26 14:31:59

标签: android android-layout android-recyclerview recycler-adapter notifydatasetchanged

我的水平RecyclerView.Adapter子类有一个简单的LinearLayout行,后面有?attr/selectableItemBackgroundBorderless

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="60dp"
          android:layout_height="match_parent"
          android:gravity="center"
          android:background="?attr/selectableItemBackgroundBorderless"
          android:orientation="vertical"
>

    <TextView/>
    <TextView/>

</LinearLayout>

视图OnClickListener的界面是从RecyclerView设置的 - 这里没什么特别的。

OnClickListener正在处理&#34;选择&#34;视图的颜色,并将一些数据传递到另一个界面:

setAdapter(new CalendarViewAdapter(view -> {
        int position = getChildLayoutPosition(view);
        if (position == selectedDayPosition) return;

        getAdapter().notifyItemChanged(selectedDayPosition);
        selectedDayPosition = position;
        getAdapter().notifyItemChanged(selectedDayPosition);

        //view.setPressed(true);  
        //view.setPressed(false); <-- That didn't help as well (nor delaying in a handler etc.)

        if (listener != null) {
            listener.onDayPicked(CalendarPicker.this.days.get(selectedDayPosition).getPaginationInfo());
        }
    }));

我担心的是notifyItemChanged()而不是涟漪的褪色,我最终得到了这个奇怪的结果:

enter image description here 在触摸事件发布时拍摄的截图

我唯一的解释是这是?attr/selectableItemBackgroundBorderless?attr/selectableItemBackground之间的一些奇怪组合。但我只想要无边框风格。

关于这个问题有几个问题,我尝试了所有的答案但不幸的是他们都使用?attr/selectableItemBackground而不是无边界的变体。

任何有关我的UI困境的帮助都将受到高度赞赏!

0 个答案:

没有答案