我有一个简单的RecyclerView
,当您LongClick
中的RecyclerView
行时,我在该行上显示了一个隐藏的LinearLayout
。为此,在我的public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent,int viewType)
中,我正在使用以下
LinearLayout REactION_LAYOUT = RecyclerItem.FindViewById<LinearLayout>(Resource.Id.reaction_layout);
RecyclerItem.LongClick += (sender,e) => { OnLongClick(REactION_LAYOUT); };
REactION_LAYOUT
是我使用以下内容显示的布局
private void OnLongClick(LinearLayout _ReactionLayout)
{
try
{
_ReactionLayout.Visibility = ViewStates.Visible;
}
catch (Exception X)
{
Log.Info("1022585","CLICK (ERROR) : " + X.Message);
}
}
这可以按预期工作,现在我想要的是,当用户触摸行外的任何地方时,隐藏REactION_LAYOUT
,这意味着RecyclerView中的其他行或其他任何地方
我该怎么做?
我尝试使用的方法是检测适配器parent
中OnCreateViewHolder
的触摸,如下所示
parent.Click += (sender,e) => { OnParentClick(REactION_LAYOUT); };
这有效,但是它禁用了回收站视图上的滚动。
实现此目标的最佳方法是什么?
编辑:以下是活动RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/main_message_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical">
<include layout="@layout/toolbar_messages"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="4.5dp"
android:layout_marginTop="3dp"
android:background="@drawable/shadow"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:layout_alignParentTop="true"
android:paddingBottom="70dp"/> .......
编辑2:
还尝试设置OnTouchLisener,但仍然没有运气
public class _OnRecylerTouch_Listener : Java.Lang.Object,View.IOnTouchListener
{
private LinearLayout _L;
public _OnRecylerTouch_Listener(LinearLayout L)
{
_L = L;
}
public bool OnTouch(View v,MotionEvent e)
{
_L.Visibility = ViewStates.Gone;
return true;
}
}