1

可绘制/波纹.xml

<?xml version="1.0" encoding="utf-8"?>
<!--pre Lollipop unable to ripple-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape>
            <solid android:color="@color/clickstate" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="@color/white" />
        </shape>
    </item>
</selector>

可绘制-v21/ripple.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">


    <item
        android:id="@android:id/mask"
        android:drawable="@color/white"/>

</ripple>

布局/list_items

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ripple"
    android:clickable="true"
    android:gravity="center_vertical"
    android:orientation="horizontal"/>

................

我尝试使用上面的代码在 pre-L 和 Lollipop 中添加涟漪效果。
但我只有在onLongClickListener时才会产生连锁反应,在onClick上看不到

有什么问题。这是我的 java 代码,它只显示常见的 recyclerview 。

mRecyclerView.setAdapter(mAdapter);

        RecyclerView.ItemDecoration itemDecoration =
                new DividerItemDecoration(rootView.getContext(), DividerItemDecoration.VERTICAL_LIST);
        mRecyclerView.addItemDecoration(itemDecoration);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());


// Customized Click Listener
public static interface ClickListener {

        public void onClick(View view, int position);
        public void onLongClick(View view, int position);
    }
    static class  RecyclerTouchListener implements RecyclerView.OnItemTouchListener{

        private GestureDetector gestureDetector;
        private ClickListener clickListener;

        public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
            this.clickListener = clickListener;



            gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapUp(MotionEvent e) {

                        return true;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                    View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                    if (child != null && clickListener != null) {
                        clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                    }
                }
            });
        }

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

            View child = rv.findChildViewUnder(e.getX(), e.getY());
            if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
                clickListener.onClick(child, rv.getChildPosition(child));
            }
            return false;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {


        }
    } 
4

0 回答 0