Android layout 回收器视图项目未显示涟漪效应/触摸突出显示,我使用手势减损器应用了侦听器
recyclerView.addOnItemTouchListener(新建MyListClickListener(getContext(),新建MyListClickListener.ClickListener()){ @凌驾 公共void onClick(视图v,内部位置){ 公共类MyListClickListener实现RecyclerView.OnItemTouchListener{Android layout 回收器视图项目未显示涟漪效应/触摸突出显示,我使用手势减损器应用了侦听器,android-layout,android-recyclerview,recyclerview-layout,Android Layout,Android Recyclerview,Recyclerview Layout,recyclerView.addOnItemTouchListener(新建MyListClickListener(getContext(),新建MyListClickListener.ClickListener()){ @凌驾 公共void onClick(视图v,内部位置){ 公共类MyListClickListener实现RecyclerView.OnItemTouchListener{ private GestureDetector gestureDetector; ClickListe
private GestureDetector gestureDetector;
ClickListener clickListener;
public MyListClickListener(Context context, ClickListener clickListener){
this.clickListener = clickListener;
gestureDetector = new GestureDetector(context,new GestureDetector.SimpleOnGestureListener(){
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@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 true;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
public interface ClickListener {
void onClick(View v, int position);
}
}我认为您正在寻找连锁反应。只需在drawable中创建一个xml文件(ripple.xml),并在其中编写此代码
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white"
>
</item>
</ripple>
就像在我的例子中,我只有TextView,在父标记中,我声明这两行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple"
android:clickable="true"
>
<TextView
android:id="@+id/textView_Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textColor="@color/colorPrimary"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
最后,结果是:
请看此视频:
我认为您正在寻找连锁反应。只需在drawable中创建一个xml文件(ripple.xml),并在其中编写此代码
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white"
>
</item>
</ripple>
就像在我的例子中,我只有TextView,在父标记中,我声明这两行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple"
android:clickable="true"
>
<TextView
android:id="@+id/textView_Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textColor="@color/colorPrimary"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
/>
</LinearLayout>
最后,结果是:
请看此视频:
您刚刚在Recyclar项目布局根视图中添加了两行
android:clickable="true"
android:foreground="?android:selectableItemBackground"
<LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="30dp"
android:clickable="true"
android:foreground="?android:selectableItemBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="20dp" />
</LinearLayout>
android:clickable=“true”
android:前台=“?android:selectableItemBackground”
您刚刚在Recyclar项目布局根视图中添加了两行
android:clickable="true"
android:foreground="?android:selectableItemBackground"
<LinearLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="30dp"
android:clickable="true"
android:foreground="?android:selectableItemBackground">
<TextView
android:layout_width="match_parent"
android:layout_height="20dp" />
</LinearLayout>
android:clickable=“true”
android:前台=“?android:selectableItemBackground”