在视图外部或屏幕上其他任何地方单击时,如何在Recyclerview的子视图之一中隐藏子视图?

I'm working on an android application where I have implemented a Recyclerview with few views grouped in each child.(Please view the images linked here), RecyclerviewItems. When clicked on the 'More options' icon which is on the rightmost corner, it will make 'actions' layout visible which was invisible. ActionItemsVisibleWhenMoreOptionsIsClicked. What I want to know is, how to make the 'actions' layout invisible again when user touches/clicks outside of that layout. It may be a click on other item in the Recyclerview or may be a click on outside the Recyclerview.

以下是我的子架构的布局xml。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/pure_white"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/task_detail_layout"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:orientation="horizontal"
            android:weightSum="5">

            <View
                android:id="@+id/priority_view"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.15"
                android:background="@color/high" />

            <TextView
                android:id="@+id/task_description"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4.35"
                android:background="@color/pure_white"
                android:hint="@string/task_description_dummy"
                android:padding="10dp"
                android:layout_gravity="center"
                android:textSize="16sp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical|end"
            android:paddingStart="20dp">

            <LinearLayout
                android:id="@+id/actions"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@color/pure_white"
                android:orientation="horizontal"
                android:paddingStart="20dp"
                android:visibility="gone">

                <ImageView
                    android:id="@+id/done_task"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:src="@drawable/ic_done_task" />

                <ImageView
                    android:id="@+id/edit_task"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginStart="8dp"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:src="@drawable/ic_edit_task" />

                <ImageView
                    android:id="@+id/delete_task"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginStart="8dp"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:src="@drawable/ic_delete_task" />

                <ImageView
                    android:id="@+id/empty_view"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginStart="8dp"/>

            </LinearLayout>
        </LinearLayout>

        <ImageView
            android:id="@+id/more_options"
            android:layout_width="30dp"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical|end"
            android:backgroundTint="@color/pure_white"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/ic_more_options" />
    </FrameLayout>

    <View
        android:id="@+id/horizontal_line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/light_gray" />

</LinearLayout>

以下是我的适配器

public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.MyViewHolder> {

private List<Task> tasks;
private Context context;

static class MyViewHolder extends RecyclerView.ViewHolder {

    LinearLayout taskDetailLayout;
    View priorityView;
    TextView taskDescriptionView;
    ImageView moreOptions;
    LinearLayout actions;
    ImageView markTaskCompleted;
    ImageView editTask;
    ImageView deleteTask;

    MyViewHolder(View view) {
        super(view);
        taskDetailLayout = view.findViewById(R.id.task_detail_layout);
        priorityView = view.findViewById(R.id.priority_view);
        taskDescriptionView = view.findViewById(R.id.task_description);
        moreOptions = view.findViewById(R.id.more_options);
        actions = view.findViewById(R.id.actions);
        markTaskCompleted = view.findViewById(R.id.done_task);
        editTask = view.findViewById(R.id.edit_task);
        deleteTask = view.findViewById(R.id.delete_task);
    }

}

public TaskAdapter(List<Task> items, Context context) {
    this.tasks = items;
    this.context = context;
    setHasStableIds(true);
}

public void refreshTaskList(List<Task> tasks) {
    this.tasks = tasks;
    notifyDataSetChanged();
}

@NonNull
@Override
public TaskAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.task_schema, parent, false);
    return new TaskAdapter.MyViewHolder(itemView);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public int getItemViewType(int position) {
    return position;
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
    Task currentTask = tasks.get(position);

    if (null != currentTask) {
        String taskDescription = currentTask.getDescription();
        String priority = currentTask.getPriority();
        boolean isTaskCompleted = currentTask.isTaskCompleted();
        int priorityColor = PRIORITY_LOW.equalsIgnoreCase(priority) ? context.getResources().getColor(R.color.low) :
                (PRIORITY_MEDIUM.equalsIgnoreCase(priority) ? context.getResources().getColor(R.color.medium) :
                        context.getResources().getColor(R.color.high));

        holder.taskDescriptionView.setText(taskDescription);
        holder.priorityView.setBackgroundColor(priorityColor);

        // When user clicks 'More Options' icon show the action icons
        holder.moreOptions.setOnClickListener(v -> {
            holder.actions.setVisibility(View.VISIBLE);
            holder.taskDetailLayout.setAlpha(0.7F);
            holder.taskDescriptionView.setAlpha(0.7F);
            holder.taskDetailLayout.setBackgroundColor(context.getResources().getColor(R.color.dim_description_color));
            holder.taskDescriptionView.setBackgroundColor(context.getResources().getColor(R.color.dim_description_color));
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.right_to_left_anim);
            holder.actions.startAnimation(animation);
        });


        // Mark Task related logic
        // If task is already completed, show done_mark icon and hide edit icon
        if (isTaskCompleted) {
            holder.markTaskCompleted.setOnClickListener(null);
            holder.markTaskCompleted.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_mark));
            holder.editTask.setVisibility(View.GONE);
        } else {
            // When user clicks 'Mark Done' icon show the popup
            holder.markTaskCompleted.setOnClickListener(v -> {
                new AlertDialog.Builder(context)
                        .setTitle("Mark Completed")
                        .setMessage("Nice, Have you completed the task?")
                        .setNegativeButton("No", null)
                        .setPositiveButton("Yes", (arg0, arg1) -> {
                            TaskHelper.markTaskCompleted(context, currentTask.getId());
                            holder.markTaskCompleted.setOnClickListener(null);
                            holder.markTaskCompleted.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_done_mark));
                            holder.editTask.setVisibility(View.GONE);
                        }).create().show();
                ;
            });
        }

        // Delete task related logic
        // When user clicks 'Delete task' icon
        holder.deleteTask.setOnClickListener(v -> {
            new AlertDialog.Builder(context)
                    .setTitle("Delete task")
                    .setMessage("Are you sure want to delete the task?")
                    .setNegativeButton("No", null)
                    .setPositiveButton("Yes", (arg0, arg1) -> {
                        new HomeScreenActivity().deleteTask(context, currentTask.getId());
                        holder.actions.setVisibility(View.VISIBLE);
                    }).create().show();
        });

        // Edit task related logic
        holder.editTask.setOnClickListener(v -> {
            Intent editIntent = new Intent(context, AddNewTaskActivity.class);
            editIntent.putExtra(TASK_ID, currentTask.getId());
            context.startActivity(editIntent);
        });

    }

}


@Override
public int getItemCount() {
    return tasks.size();
}

}

我需要可以在适配器或活动中实现的逻辑/功能。