Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在RecyclerView中触摸动画不会';行不通_Android_Android Animation_Android Recyclerview - Fatal编程技术网

Android 在RecyclerView中触摸动画不会';行不通

Android 在RecyclerView中触摸动画不会';行不通,android,android-animation,android-recyclerview,Android,Android Animation,Android Recyclerview,在我的列表xml项中,我设置了以下代码: android:foreground="?android:attr/selectableItemBackground" android:clickable="true" android:focusable="true" 当我按下RecyclerView项时,它会产生一些涟漪动画。 要获取项目,请单击我使用的此类: public class RecyclerItemClickListener implements RecyclerView.OnItemT

在我的列表xml项中,我设置了以下代码:

android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
当我按下RecyclerView项时,它会产生一些涟漪动画。
要获取项目,请单击我使用的此类:

public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;

public interface OnItemClickListener {
    public void onItemClick(View view, int position);
}

GestureDetector mGestureDetector;

public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
    mListener = listener;
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });
}

@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
    }
    return false;
}

@Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

}
}
并使用如下示例:

rv.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    Log.d("OnClick", "click at " + position);
                    Intent intent = new Intent(getActivity(), DetailEventActivity.class);
                    intent.putExtra("EVENT", list.get(position - 1));
                    startActivity(intent);
                }
            }));
这是我使用RecyclerView的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rv"
        />

</RelativeLayout>

这是我的项目布局的布局:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/text_color"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"
    >

    <de.hdodenhof.circleimageview.CircleImageView
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="20dp"
        android:id="@+id/event_card_icon"
        android:src="@mipmap/ic_launcher" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.devspark.robototextview.widget.RobotoTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add 500 rub"
            android:textSize="17sp"
            app:typeface="roboto_light"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="72dp"
            android:textColor="#7a7a7a"
            android:id="@+id/event_description"
            android:layout_toLeftOf="@+id/ic_replay"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <com.devspark.robototextview.widget.RobotoTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/time_of_publish"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="72dp"
            android:text="@string/time"
            android:textColor="#b8b8b8"
            app:typeface="roboto_regular"
            android:layout_below="@id/event_description"/>

        <com.devspark.robototextview.widget.RobotoTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="+4"
            android:textSize="12sp"
            app:typeface="roboto_regular"
            android:drawableRight="@drawable/ic_points_small"
            android:textColor="#cccccc"
            android:drawablePadding="5dp"
            android:layout_alignBottom="@+id/time_of_publish"
            android:layout_alignParentRight="true"
            android:layout_marginRight="16dp"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ic_replay"
            android:layout_alignTop="@+id/event_description"
            android:layout_marginRight="16dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />


        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/time_of_publish"
            android:id="@+id/divider2"
            android:layout_marginLeft="72dp"
            android:layout_marginTop="20dp"
            android:background="#ebebeb"
            />

    </RelativeLayout>

</RelativeLayout>

我看到了很多问题和答案,我不知道为什么这个代码不起作用。也许有人能帮我


我的问题是按RecyclerView项上的动画按钮。查看项对我不起作用。

在drawable-v21文件夹中创建一个ripple drawable,id掩码用于将涟漪效果限制在您单击的行的边界内: ripple_drawable.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
  android:color="your rippleeffect color">
<item android:id="@android:id/mask"
     android:drawable="@android:color/white" />

你的log.d(“OnClick”,“click at”+位置);包含点击项目的位置?你的问题是ripple动画不起作用?哇…真的没有人回答你的问题吗?你找到解决办法了吗?
android:background="@drawable/ripple_drawable"