I have a simple RecyclerView
and when you LongClick
a Row in RecyclerView
I make a hidden LinearLayout
visible on that row.
(我有一个简单RecyclerView
,当你LongClick
在连续RecyclerView
我做一个隐藏LinearLayout
可见该行。)
To do so In my public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
I am using the following (这样做在我的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
is the layout I am showing using the following
(REACTION_LAYOUT
是我使用以下内容显示的布局)
private void OnLongClick(LinearLayout _ReactionLayout)
{
try
{
_ReactionLayout.Visibility = ViewStates.Visible;
}
catch (Exception X)
{
Log.Info("1022585", "CLICK (ERROR) : " + X.Message);
}
}
This works as Intended, Now what I want is to HIDE the REACTION_LAYOUT
when a user touches anywhere outside the Row which means on other rows in RecyclerView or anywhere else
(这按预期工作,现在我想要的是当用户触摸行外的任何地方时都隐藏REACTION_LAYOUT
,这意味着RecyclerView中的其他行或其他任何地方)
How do I do that?
(我怎么做?)
The approach I tried to use was to detect a touch on parent
within my Adapter's OnCreateViewHolder
as following
(我尝试使用的方法是在适配器的OnCreateViewHolder
检测对parent
的触摸,如下所示)
parent.Click += (sender, e) => { OnParentClick(REACTION_LAYOUT); };
This works but It disables the scrolling on recycler view.
(这可以工作,但是会禁用“回收者”视图上的滚动。)
What is the best way to achieve this?
(实现此目标的最佳方法是什么?)
EDIT : The activity RecyclerView is the following
(编辑 :活动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"/> .......
ask by Ali translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…