How to pass Click Events to overlapping views in framelayout










0















Here I have made a RecyclerView , each row in list consist of frameLayout with two primary child layout (Background RelativeLayout and foreGround RelativeLayout) overlapping each other .



Using ItemTouchHelper.SimpleCallback ,I am swiping the foreground layout to reveal the background layout .



I am not able to get ClickEvent on any of the entities in background . Please find code



list_row.xml



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- android:paddingStart="?listPreferredItemPaddingLeft"
android:paddingTop="@dimen/padding_list_row"
android:paddingEnd="?listPreferredItemPaddingRight"
android:paddingBottom="@dimen/padding_list_row"-->

<RelativeLayout
android:id="@+id/view_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mailSwipeMenu">

<LinearLayout
android:id="@+id/right_swipe_options_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">

<RelativeLayout
android:id="@+id/unread_btn_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/padding_10"
android:layout_marginEnd="@dimen/padding_10"
android:gravity="center">

<ImageView
android:id="@+id/mark_unread_icon"
android:layout_width="@dimen/icon_delete"
android:layout_height="@dimen/icon_delete"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/padding_6"
android:src="@drawable/icon_read_button" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/mark_unread_icon"
android:layout_centerHorizontal="true"
android:text="@string/mark_as_unread"
android:textColor="#fff"
android:textSize="@dimen/text_icon" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/spam_btn_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/padding_10"
android:layout_marginEnd="@dimen/padding_10"
android:gravity="center">

<ImageView
android:id="@+id/report_spam_icon"
android:layout_width="@dimen/icon_delete"
android:layout_height="@dimen/icon_delete"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/padding_6"
android:src="@drawable/icon_spam_button" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/report_spam_icon"
android:layout_centerHorizontal="true"
android:text="@string/report_spam"
android:textColor="#fff"
android:textSize="@dimen/text_icon" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/move_btn_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/padding_10"
android:layout_marginEnd="@dimen/padding_10"
android:gravity="center">

<ImageView
android:id="@+id/move_mail_icon"
android:layout_width="@dimen/icon_delete"
android:layout_height="@dimen/icon_delete"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/padding_6"
android:src="@drawable/icon_move_button" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/move_mail_icon"
android:layout_centerHorizontal="true"
android:text="@string/move_mail"
android:textColor="#fff"
android:textSize="@dimen/text_icon" />
</RelativeLayout>


</LinearLayout>

<RelativeLayout
android:id="@+id/left_swipe_options_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/padding_10"
android:gravity="center"
android:visibility="gone">

<ImageView
android:id="@+id/delete_icon"
android:layout_width="@dimen/icon_delete"
android:layout_height="@dimen/icon_delete"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/padding_6"
android:src="@drawable/icon_delete_button" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/delete_icon"
android:layout_centerHorizontal="true"
android:text="@string/delete"
android:textColor="#fff"
android:textSize="@dimen/text_icon" />
</RelativeLayout>

</RelativeLayout>

<RelativeLayout
android:id="@+id/view_foreground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_list_row_inbox"
android:orientation="vertical"
android:padding="@dimen/padding_10">

<LinearLayout
android:id="@+id/message_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="72dp"
android:paddingEnd="@dimen/padding_list_row">

<TextView
android:id="@+id/from"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@color/from"
android:textSize="@dimen/msg_text_primary"
android:textStyle="bold" />

<TextView
android:id="@+id/txt_primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@color/subject"
android:textSize="@dimen/msg_text_secondary"
android:textStyle="bold" />

<TextView
android:id="@+id/txt_secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@color/message"
android:textSize="@dimen/msg_text_secondary" />

</LinearLayout>

<RelativeLayout
android:id="@+id/select_icon_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">

<RelativeLayout
android:id="@+id/icon_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:layout_width="@dimen/icon_width_height"
android:layout_height="@dimen/icon_width_height"
android:src="@drawable/bg_circle" />

<ImageView
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="@drawable/icon_check_white_24dp" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/icon_front"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/icon_profile"
android:layout_width="@dimen/icon_width_height"
android:layout_height="@dimen/icon_width_height" />

<TextView
android:id="@+id/icon_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@android:color/white"
android:textSize="@dimen/text_icon" />
</RelativeLayout>

</RelativeLayout>

<TextView
android:id="@+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:textColor="@color/timestamp"
android:textSize="@dimen/text_timestamp"
android:textStyle="bold" />

<ImageView
android:id="@+id/icon_star"
android:layout_width="@dimen/icon_star"
android:layout_height="@dimen/icon_star"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:tint="@color/icon_tint_normal" />

</RelativeLayout>

</FrameLayout>


RecyclerItemTouchHelper.kt



 open class RecyclerItemTouchHelper(dragDirs: Int, swipeDirs: Int, private val listener: RecyclerItemTouchHelperListener) : ItemTouchHelper.SimpleCallback(dragDirs, swipeDirs) 

override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean
return true


override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int)
if (viewHolder != null)
val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

getDefaultUIUtil().onSelected(foregroundView)



override fun onChildDrawOver(c: Canvas, recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
actionState: Int, isCurrentlyActive: Boolean)
val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
getDefaultUIUtil().onDrawOver(c, recyclerView, foregroundView, dX, dY,
actionState, isCurrentlyActive)


override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder)
val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
getDefaultUIUtil().clearView(foregroundView)
listener.onForegroundViewRestored(viewHolder,viewHolder.adapterPosition)


override fun onChildDraw(c: Canvas, recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
actionState: Int, isCurrentlyActive: Boolean)
val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

listener.onSwipeStart(viewHolder, if (dX < 0) ItemTouchHelper.LEFT else ItemTouchHelper.RIGHT, viewHolder.adapterPosition)
getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX * .9F, dY,
actionState, isCurrentlyActive)


override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int)
listener.onSwiped(viewHolder, direction, viewHolder.adapterPosition)


override fun convertToAbsoluteDirection(flags: Int, layoutDirection: Int): Int
return super.convertToAbsoluteDirection(flags, layoutDirection)




interface RecyclerItemTouchHelperListener
fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
fun onSwipeStart(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
fun onForegroundViewRestored(viewHolder: RecyclerView.ViewHolder, position: Int)




InboxListAdapter.kt



class InboxListAdapter() : RecyclerView.Adapter<InboxListAdapter.InboxItemHolder>() 


var mContext: Context? = null
private var messages = mutableListOf<InboxItemModel>()
var listener: MessageAdapterListener? = null
private var selectedItems: SparseBooleanArray? = null
private var animationItemsIndex: SparseBooleanArray? = null
private var reverseAllAnimations = false
private var currentSelectedIndex = -1

constructor(context: Context, messages: MutableList<InboxItemModel>, listener: MessageAdapterListener) : this()
this.mContext = context
this.messages = messages
this.listener = listener
selectedItems = SparseBooleanArray()
animationItemsIndex = SparseBooleanArray()


inner class InboxItemHolder(view: View) : RecyclerView.ViewHolder(view), View.OnLongClickListener ,View.OnClickListener
var viewForeground : RelativeLayout = view.findViewById<View>(R.id.view_foreground) as RelativeLayout
var viewBackGround : RelativeLayout = view.findViewById<View>(R.id.view_background) as RelativeLayout
var viewLeftSwipe : RelativeLayout = view.findViewById<View>(R.id.left_swipe_options_layout) as RelativeLayout
var viewRightSwipe : LinearLayout = view.findViewById<View>(R.id.right_swipe_options_layout) as LinearLayout
var spamButtonLayout : RelativeLayout = view.findViewById<View>(R.id.spam_btn_layout) as RelativeLayout
var moveButtonLayout : RelativeLayout = view.findViewById<View>(R.id.move_btn_layout) as RelativeLayout
var unreadButtonLayout : RelativeLayout = view.findViewById<View>(R.id.unread_btn_layout) as RelativeLayout
var deleteImageView : ImageView = view.findViewById<View>(R.id.delete_icon) as ImageView
var from: TextView = view.findViewById<View>(R.id.from) as TextView
var subject: TextView = view.findViewById<View>(R.id.txt_primary) as TextView
var message: TextView = view.findViewById<View>(R.id.txt_secondary) as TextView
var iconText: TextView = view.findViewById<View>(R.id.icon_text) as TextView
var timestamp: TextView = view.findViewById<View>(R.id.timestamp) as TextView
var iconImp: ImageView = view.findViewById<View>(R.id.icon_star) as ImageView
var imgProfile: ImageView = view.findViewById<View>(R.id.icon_profile) as ImageView
var messageContainer: LinearLayout = view.findViewById<View>(R.id.message_container) as LinearLayout
var iconContainer: RelativeLayout = view.findViewById<View>(R.id.select_icon_container) as RelativeLayout
var iconBack: RelativeLayout = view.findViewById<View>(R.id.icon_back) as RelativeLayout
var iconFront: RelativeLayout = view.findViewById<View>(R.id.icon_front) as RelativeLayout

init
view.setOnLongClickListener(this)
spamButtonLayout.setOnClickListener(this)
moveButtonLayout.setOnClickListener(this)
unreadButtonLayout.setOnClickListener(this)
viewLeftSwipe.setOnClickListener(this)
deleteImageView.setOnClickListener(this)



override fun onLongClick(view: View): Boolean
listener!!.onRowLongClicked(adapterPosition)
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
return true


override fun onClick(p0: View?)
when(p0!!.id)
R.id.spam_btn_layout -> listener!!.onSpamButtonClicked(adapterPosition)
R.id.unread_btn_layout -> listener!!.onReadButtonClicked(adapterPosition)
R.id.move_btn_layout -> listener!!.onMoveButtonClicked(adapterPosition)
R.id.left_swipe_options_layout -> listener!!.onDeleteButtonClicked(adapterPosition)
R.id.delete_icon -> listener!!.onDeleteButtonClicked(adapterPosition)





override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InboxItemHolder
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.list_row_inbox, parent, false)

return InboxItemHolder(itemView)


override fun onBindViewHolder(holder: InboxItemHolder, position: Int)
val message = messages[position]

holder.from.text = message.sender
holder.subject.text = message.subject
holder.message.text = message.subject
holder.timestamp.text = message.timeStamp
holder.itemView.isActivated = selectedItems!!.get(position, false)


[![enter image description here][1]][1]
// apply click events
applyClickEvents(holder, position)


private fun applyClickEvents(holder: InboxItemHolder, position: Int)
holder.iconContainer.setOnClickListener listener!!.onIconClicked(position)

holder.iconImp.setOnClickListener listener!!.onIconImportantClicked(position)

holder.messageContainer.setOnClickListener listener!!.onMessageRowClicked(position)

holder.messageContainer.setOnLongClickListener view ->
listener!!.onRowLongClicked(position)
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
true





Swiping the foreground layout



enter image description here










share|improve this question


























    0















    Here I have made a RecyclerView , each row in list consist of frameLayout with two primary child layout (Background RelativeLayout and foreGround RelativeLayout) overlapping each other .



    Using ItemTouchHelper.SimpleCallback ,I am swiping the foreground layout to reveal the background layout .



    I am not able to get ClickEvent on any of the entities in background . Please find code



    list_row.xml



    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <!-- android:paddingStart="?listPreferredItemPaddingLeft"
    android:paddingTop="@dimen/padding_list_row"
    android:paddingEnd="?listPreferredItemPaddingRight"
    android:paddingBottom="@dimen/padding_list_row"-->

    <RelativeLayout
    android:id="@+id/view_background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/mailSwipeMenu">

    <LinearLayout
    android:id="@+id/right_swipe_options_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:gravity="center"
    android:orientation="horizontal"
    android:visibility="gone">

    <RelativeLayout
    android:id="@+id/unread_btn_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/padding_10"
    android:layout_marginEnd="@dimen/padding_10"
    android:gravity="center">

    <ImageView
    android:id="@+id/mark_unread_icon"
    android:layout_width="@dimen/icon_delete"
    android:layout_height="@dimen/icon_delete"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="@dimen/padding_6"
    android:src="@drawable/icon_read_button" />

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/mark_unread_icon"
    android:layout_centerHorizontal="true"
    android:text="@string/mark_as_unread"
    android:textColor="#fff"
    android:textSize="@dimen/text_icon" />
    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/spam_btn_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/padding_10"
    android:layout_marginEnd="@dimen/padding_10"
    android:gravity="center">

    <ImageView
    android:id="@+id/report_spam_icon"
    android:layout_width="@dimen/icon_delete"
    android:layout_height="@dimen/icon_delete"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="@dimen/padding_6"
    android:src="@drawable/icon_spam_button" />

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/report_spam_icon"
    android:layout_centerHorizontal="true"
    android:text="@string/report_spam"
    android:textColor="#fff"
    android:textSize="@dimen/text_icon" />
    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/move_btn_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/padding_10"
    android:layout_marginEnd="@dimen/padding_10"
    android:gravity="center">

    <ImageView
    android:id="@+id/move_mail_icon"
    android:layout_width="@dimen/icon_delete"
    android:layout_height="@dimen/icon_delete"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="@dimen/padding_6"
    android:src="@drawable/icon_move_button" />

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/move_mail_icon"
    android:layout_centerHorizontal="true"
    android:text="@string/move_mail"
    android:textColor="#fff"
    android:textSize="@dimen/text_icon" />
    </RelativeLayout>


    </LinearLayout>

    <RelativeLayout
    android:id="@+id/left_swipe_options_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_centerVertical="true"
    android:layout_marginEnd="@dimen/padding_10"
    android:gravity="center"
    android:visibility="gone">

    <ImageView
    android:id="@+id/delete_icon"
    android:layout_width="@dimen/icon_delete"
    android:layout_height="@dimen/icon_delete"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="@dimen/padding_6"
    android:src="@drawable/icon_delete_button" />

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/delete_icon"
    android:layout_centerHorizontal="true"
    android:text="@string/delete"
    android:textColor="#fff"
    android:textSize="@dimen/text_icon" />
    </RelativeLayout>

    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/view_foreground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_list_row_inbox"
    android:orientation="vertical"
    android:padding="@dimen/padding_10">

    <LinearLayout
    android:id="@+id/message_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingStart="72dp"
    android:paddingEnd="@dimen/padding_list_row">

    <TextView
    android:id="@+id/from"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:lines="1"
    android:textColor="@color/from"
    android:textSize="@dimen/msg_text_primary"
    android:textStyle="bold" />

    <TextView
    android:id="@+id/txt_primary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:lines="1"
    android:textColor="@color/subject"
    android:textSize="@dimen/msg_text_secondary"
    android:textStyle="bold" />

    <TextView
    android:id="@+id/txt_secondary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:lines="1"
    android:textColor="@color/message"
    android:textSize="@dimen/msg_text_secondary" />

    </LinearLayout>

    <RelativeLayout
    android:id="@+id/select_icon_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:orientation="vertical">

    <RelativeLayout
    android:id="@+id/icon_back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
    android:layout_width="@dimen/icon_width_height"
    android:layout_height="@dimen/icon_width_height"
    android:src="@drawable/bg_circle" />

    <ImageView
    android:layout_width="25dp"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    app:srcCompat="@drawable/icon_check_white_24dp" />

    </RelativeLayout>

    <RelativeLayout
    android:id="@+id/icon_front"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
    android:id="@+id/icon_profile"
    android:layout_width="@dimen/icon_width_height"
    android:layout_height="@dimen/icon_width_height" />

    <TextView
    android:id="@+id/icon_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:textColor="@android:color/white"
    android:textSize="@dimen/text_icon" />
    </RelativeLayout>

    </RelativeLayout>

    <TextView
    android:id="@+id/timestamp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:textColor="@color/timestamp"
    android:textSize="@dimen/text_timestamp"
    android:textStyle="bold" />

    <ImageView
    android:id="@+id/icon_star"
    android:layout_width="@dimen/icon_star"
    android:layout_height="@dimen/icon_star"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:tint="@color/icon_tint_normal" />

    </RelativeLayout>

    </FrameLayout>


    RecyclerItemTouchHelper.kt



     open class RecyclerItemTouchHelper(dragDirs: Int, swipeDirs: Int, private val listener: RecyclerItemTouchHelperListener) : ItemTouchHelper.SimpleCallback(dragDirs, swipeDirs) 

    override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean
    return true


    override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int)
    if (viewHolder != null)
    val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

    getDefaultUIUtil().onSelected(foregroundView)



    override fun onChildDrawOver(c: Canvas, recyclerView: RecyclerView,
    viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
    actionState: Int, isCurrentlyActive: Boolean)
    val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
    getDefaultUIUtil().onDrawOver(c, recyclerView, foregroundView, dX, dY,
    actionState, isCurrentlyActive)


    override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder)
    val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
    getDefaultUIUtil().clearView(foregroundView)
    listener.onForegroundViewRestored(viewHolder,viewHolder.adapterPosition)


    override fun onChildDraw(c: Canvas, recyclerView: RecyclerView,
    viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
    actionState: Int, isCurrentlyActive: Boolean)
    val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

    listener.onSwipeStart(viewHolder, if (dX < 0) ItemTouchHelper.LEFT else ItemTouchHelper.RIGHT, viewHolder.adapterPosition)
    getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX * .9F, dY,
    actionState, isCurrentlyActive)


    override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int)
    listener.onSwiped(viewHolder, direction, viewHolder.adapterPosition)


    override fun convertToAbsoluteDirection(flags: Int, layoutDirection: Int): Int
    return super.convertToAbsoluteDirection(flags, layoutDirection)




    interface RecyclerItemTouchHelperListener
    fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
    fun onSwipeStart(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
    fun onForegroundViewRestored(viewHolder: RecyclerView.ViewHolder, position: Int)




    InboxListAdapter.kt



    class InboxListAdapter() : RecyclerView.Adapter<InboxListAdapter.InboxItemHolder>() 


    var mContext: Context? = null
    private var messages = mutableListOf<InboxItemModel>()
    var listener: MessageAdapterListener? = null
    private var selectedItems: SparseBooleanArray? = null
    private var animationItemsIndex: SparseBooleanArray? = null
    private var reverseAllAnimations = false
    private var currentSelectedIndex = -1

    constructor(context: Context, messages: MutableList<InboxItemModel>, listener: MessageAdapterListener) : this()
    this.mContext = context
    this.messages = messages
    this.listener = listener
    selectedItems = SparseBooleanArray()
    animationItemsIndex = SparseBooleanArray()


    inner class InboxItemHolder(view: View) : RecyclerView.ViewHolder(view), View.OnLongClickListener ,View.OnClickListener
    var viewForeground : RelativeLayout = view.findViewById<View>(R.id.view_foreground) as RelativeLayout
    var viewBackGround : RelativeLayout = view.findViewById<View>(R.id.view_background) as RelativeLayout
    var viewLeftSwipe : RelativeLayout = view.findViewById<View>(R.id.left_swipe_options_layout) as RelativeLayout
    var viewRightSwipe : LinearLayout = view.findViewById<View>(R.id.right_swipe_options_layout) as LinearLayout
    var spamButtonLayout : RelativeLayout = view.findViewById<View>(R.id.spam_btn_layout) as RelativeLayout
    var moveButtonLayout : RelativeLayout = view.findViewById<View>(R.id.move_btn_layout) as RelativeLayout
    var unreadButtonLayout : RelativeLayout = view.findViewById<View>(R.id.unread_btn_layout) as RelativeLayout
    var deleteImageView : ImageView = view.findViewById<View>(R.id.delete_icon) as ImageView
    var from: TextView = view.findViewById<View>(R.id.from) as TextView
    var subject: TextView = view.findViewById<View>(R.id.txt_primary) as TextView
    var message: TextView = view.findViewById<View>(R.id.txt_secondary) as TextView
    var iconText: TextView = view.findViewById<View>(R.id.icon_text) as TextView
    var timestamp: TextView = view.findViewById<View>(R.id.timestamp) as TextView
    var iconImp: ImageView = view.findViewById<View>(R.id.icon_star) as ImageView
    var imgProfile: ImageView = view.findViewById<View>(R.id.icon_profile) as ImageView
    var messageContainer: LinearLayout = view.findViewById<View>(R.id.message_container) as LinearLayout
    var iconContainer: RelativeLayout = view.findViewById<View>(R.id.select_icon_container) as RelativeLayout
    var iconBack: RelativeLayout = view.findViewById<View>(R.id.icon_back) as RelativeLayout
    var iconFront: RelativeLayout = view.findViewById<View>(R.id.icon_front) as RelativeLayout

    init
    view.setOnLongClickListener(this)
    spamButtonLayout.setOnClickListener(this)
    moveButtonLayout.setOnClickListener(this)
    unreadButtonLayout.setOnClickListener(this)
    viewLeftSwipe.setOnClickListener(this)
    deleteImageView.setOnClickListener(this)



    override fun onLongClick(view: View): Boolean
    listener!!.onRowLongClicked(adapterPosition)
    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
    return true


    override fun onClick(p0: View?)
    when(p0!!.id)
    R.id.spam_btn_layout -> listener!!.onSpamButtonClicked(adapterPosition)
    R.id.unread_btn_layout -> listener!!.onReadButtonClicked(adapterPosition)
    R.id.move_btn_layout -> listener!!.onMoveButtonClicked(adapterPosition)
    R.id.left_swipe_options_layout -> listener!!.onDeleteButtonClicked(adapterPosition)
    R.id.delete_icon -> listener!!.onDeleteButtonClicked(adapterPosition)





    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InboxItemHolder
    val itemView = LayoutInflater.from(parent.context)
    .inflate(R.layout.list_row_inbox, parent, false)

    return InboxItemHolder(itemView)


    override fun onBindViewHolder(holder: InboxItemHolder, position: Int)
    val message = messages[position]

    holder.from.text = message.sender
    holder.subject.text = message.subject
    holder.message.text = message.subject
    holder.timestamp.text = message.timeStamp
    holder.itemView.isActivated = selectedItems!!.get(position, false)


    [![enter image description here][1]][1]
    // apply click events
    applyClickEvents(holder, position)


    private fun applyClickEvents(holder: InboxItemHolder, position: Int)
    holder.iconContainer.setOnClickListener listener!!.onIconClicked(position)

    holder.iconImp.setOnClickListener listener!!.onIconImportantClicked(position)

    holder.messageContainer.setOnClickListener listener!!.onMessageRowClicked(position)

    holder.messageContainer.setOnLongClickListener view ->
    listener!!.onRowLongClicked(position)
    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
    true





    Swiping the foreground layout



    enter image description here










    share|improve this question
























      0












      0








      0








      Here I have made a RecyclerView , each row in list consist of frameLayout with two primary child layout (Background RelativeLayout and foreGround RelativeLayout) overlapping each other .



      Using ItemTouchHelper.SimpleCallback ,I am swiping the foreground layout to reveal the background layout .



      I am not able to get ClickEvent on any of the entities in background . Please find code



      list_row.xml



      <?xml version="1.0" encoding="utf-8"?>
      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">
      <!-- android:paddingStart="?listPreferredItemPaddingLeft"
      android:paddingTop="@dimen/padding_list_row"
      android:paddingEnd="?listPreferredItemPaddingRight"
      android:paddingBottom="@dimen/padding_list_row"-->

      <RelativeLayout
      android:id="@+id/view_background"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/mailSwipeMenu">

      <LinearLayout
      android:id="@+id/right_swipe_options_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:gravity="center"
      android:orientation="horizontal"
      android:visibility="gone">

      <RelativeLayout
      android:id="@+id/unread_btn_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="@dimen/padding_10"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center">

      <ImageView
      android:id="@+id/mark_unread_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_read_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/mark_unread_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/mark_as_unread"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/spam_btn_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="@dimen/padding_10"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center">

      <ImageView
      android:id="@+id/report_spam_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_spam_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/report_spam_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/report_spam"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/move_btn_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="@dimen/padding_10"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center">

      <ImageView
      android:id="@+id/move_mail_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_move_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/move_mail_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/move_mail"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>


      </LinearLayout>

      <RelativeLayout
      android:id="@+id/left_swipe_options_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentEnd="true"
      android:layout_centerVertical="true"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center"
      android:visibility="gone">

      <ImageView
      android:id="@+id/delete_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_delete_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/delete_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/delete"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/view_foreground"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/bg_list_row_inbox"
      android:orientation="vertical"
      android:padding="@dimen/padding_10">

      <LinearLayout
      android:id="@+id/message_container"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingStart="72dp"
      android:paddingEnd="@dimen/padding_list_row">

      <TextView
      android:id="@+id/from"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:lines="1"
      android:textColor="@color/from"
      android:textSize="@dimen/msg_text_primary"
      android:textStyle="bold" />

      <TextView
      android:id="@+id/txt_primary"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:lines="1"
      android:textColor="@color/subject"
      android:textSize="@dimen/msg_text_secondary"
      android:textStyle="bold" />

      <TextView
      android:id="@+id/txt_secondary"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:lines="1"
      android:textColor="@color/message"
      android:textSize="@dimen/msg_text_secondary" />

      </LinearLayout>

      <RelativeLayout
      android:id="@+id/select_icon_container"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:orientation="vertical">

      <RelativeLayout
      android:id="@+id/icon_back"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <ImageView
      android:layout_width="@dimen/icon_width_height"
      android:layout_height="@dimen/icon_width_height"
      android:src="@drawable/bg_circle" />

      <ImageView
      android:layout_width="25dp"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      app:srcCompat="@drawable/icon_check_white_24dp" />

      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/icon_front"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <ImageView
      android:id="@+id/icon_profile"
      android:layout_width="@dimen/icon_width_height"
      android:layout_height="@dimen/icon_width_height" />

      <TextView
      android:id="@+id/icon_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:textColor="@android:color/white"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      </RelativeLayout>

      <TextView
      android:id="@+id/timestamp"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentEnd="true"
      android:textColor="@color/timestamp"
      android:textSize="@dimen/text_timestamp"
      android:textStyle="bold" />

      <ImageView
      android:id="@+id/icon_star"
      android:layout_width="@dimen/icon_star"
      android:layout_height="@dimen/icon_star"
      android:layout_alignParentEnd="true"
      android:layout_alignParentBottom="true"
      android:tint="@color/icon_tint_normal" />

      </RelativeLayout>

      </FrameLayout>


      RecyclerItemTouchHelper.kt



       open class RecyclerItemTouchHelper(dragDirs: Int, swipeDirs: Int, private val listener: RecyclerItemTouchHelperListener) : ItemTouchHelper.SimpleCallback(dragDirs, swipeDirs) 

      override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean
      return true


      override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int)
      if (viewHolder != null)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

      getDefaultUIUtil().onSelected(foregroundView)



      override fun onChildDrawOver(c: Canvas, recyclerView: RecyclerView,
      viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
      actionState: Int, isCurrentlyActive: Boolean)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
      getDefaultUIUtil().onDrawOver(c, recyclerView, foregroundView, dX, dY,
      actionState, isCurrentlyActive)


      override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
      getDefaultUIUtil().clearView(foregroundView)
      listener.onForegroundViewRestored(viewHolder,viewHolder.adapterPosition)


      override fun onChildDraw(c: Canvas, recyclerView: RecyclerView,
      viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
      actionState: Int, isCurrentlyActive: Boolean)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

      listener.onSwipeStart(viewHolder, if (dX < 0) ItemTouchHelper.LEFT else ItemTouchHelper.RIGHT, viewHolder.adapterPosition)
      getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX * .9F, dY,
      actionState, isCurrentlyActive)


      override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int)
      listener.onSwiped(viewHolder, direction, viewHolder.adapterPosition)


      override fun convertToAbsoluteDirection(flags: Int, layoutDirection: Int): Int
      return super.convertToAbsoluteDirection(flags, layoutDirection)




      interface RecyclerItemTouchHelperListener
      fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
      fun onSwipeStart(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
      fun onForegroundViewRestored(viewHolder: RecyclerView.ViewHolder, position: Int)




      InboxListAdapter.kt



      class InboxListAdapter() : RecyclerView.Adapter<InboxListAdapter.InboxItemHolder>() 


      var mContext: Context? = null
      private var messages = mutableListOf<InboxItemModel>()
      var listener: MessageAdapterListener? = null
      private var selectedItems: SparseBooleanArray? = null
      private var animationItemsIndex: SparseBooleanArray? = null
      private var reverseAllAnimations = false
      private var currentSelectedIndex = -1

      constructor(context: Context, messages: MutableList<InboxItemModel>, listener: MessageAdapterListener) : this()
      this.mContext = context
      this.messages = messages
      this.listener = listener
      selectedItems = SparseBooleanArray()
      animationItemsIndex = SparseBooleanArray()


      inner class InboxItemHolder(view: View) : RecyclerView.ViewHolder(view), View.OnLongClickListener ,View.OnClickListener
      var viewForeground : RelativeLayout = view.findViewById<View>(R.id.view_foreground) as RelativeLayout
      var viewBackGround : RelativeLayout = view.findViewById<View>(R.id.view_background) as RelativeLayout
      var viewLeftSwipe : RelativeLayout = view.findViewById<View>(R.id.left_swipe_options_layout) as RelativeLayout
      var viewRightSwipe : LinearLayout = view.findViewById<View>(R.id.right_swipe_options_layout) as LinearLayout
      var spamButtonLayout : RelativeLayout = view.findViewById<View>(R.id.spam_btn_layout) as RelativeLayout
      var moveButtonLayout : RelativeLayout = view.findViewById<View>(R.id.move_btn_layout) as RelativeLayout
      var unreadButtonLayout : RelativeLayout = view.findViewById<View>(R.id.unread_btn_layout) as RelativeLayout
      var deleteImageView : ImageView = view.findViewById<View>(R.id.delete_icon) as ImageView
      var from: TextView = view.findViewById<View>(R.id.from) as TextView
      var subject: TextView = view.findViewById<View>(R.id.txt_primary) as TextView
      var message: TextView = view.findViewById<View>(R.id.txt_secondary) as TextView
      var iconText: TextView = view.findViewById<View>(R.id.icon_text) as TextView
      var timestamp: TextView = view.findViewById<View>(R.id.timestamp) as TextView
      var iconImp: ImageView = view.findViewById<View>(R.id.icon_star) as ImageView
      var imgProfile: ImageView = view.findViewById<View>(R.id.icon_profile) as ImageView
      var messageContainer: LinearLayout = view.findViewById<View>(R.id.message_container) as LinearLayout
      var iconContainer: RelativeLayout = view.findViewById<View>(R.id.select_icon_container) as RelativeLayout
      var iconBack: RelativeLayout = view.findViewById<View>(R.id.icon_back) as RelativeLayout
      var iconFront: RelativeLayout = view.findViewById<View>(R.id.icon_front) as RelativeLayout

      init
      view.setOnLongClickListener(this)
      spamButtonLayout.setOnClickListener(this)
      moveButtonLayout.setOnClickListener(this)
      unreadButtonLayout.setOnClickListener(this)
      viewLeftSwipe.setOnClickListener(this)
      deleteImageView.setOnClickListener(this)



      override fun onLongClick(view: View): Boolean
      listener!!.onRowLongClicked(adapterPosition)
      view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
      return true


      override fun onClick(p0: View?)
      when(p0!!.id)
      R.id.spam_btn_layout -> listener!!.onSpamButtonClicked(adapterPosition)
      R.id.unread_btn_layout -> listener!!.onReadButtonClicked(adapterPosition)
      R.id.move_btn_layout -> listener!!.onMoveButtonClicked(adapterPosition)
      R.id.left_swipe_options_layout -> listener!!.onDeleteButtonClicked(adapterPosition)
      R.id.delete_icon -> listener!!.onDeleteButtonClicked(adapterPosition)





      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InboxItemHolder
      val itemView = LayoutInflater.from(parent.context)
      .inflate(R.layout.list_row_inbox, parent, false)

      return InboxItemHolder(itemView)


      override fun onBindViewHolder(holder: InboxItemHolder, position: Int)
      val message = messages[position]

      holder.from.text = message.sender
      holder.subject.text = message.subject
      holder.message.text = message.subject
      holder.timestamp.text = message.timeStamp
      holder.itemView.isActivated = selectedItems!!.get(position, false)


      [![enter image description here][1]][1]
      // apply click events
      applyClickEvents(holder, position)


      private fun applyClickEvents(holder: InboxItemHolder, position: Int)
      holder.iconContainer.setOnClickListener listener!!.onIconClicked(position)

      holder.iconImp.setOnClickListener listener!!.onIconImportantClicked(position)

      holder.messageContainer.setOnClickListener listener!!.onMessageRowClicked(position)

      holder.messageContainer.setOnLongClickListener view ->
      listener!!.onRowLongClicked(position)
      view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
      true





      Swiping the foreground layout



      enter image description here










      share|improve this question














      Here I have made a RecyclerView , each row in list consist of frameLayout with two primary child layout (Background RelativeLayout and foreGround RelativeLayout) overlapping each other .



      Using ItemTouchHelper.SimpleCallback ,I am swiping the foreground layout to reveal the background layout .



      I am not able to get ClickEvent on any of the entities in background . Please find code



      list_row.xml



      <?xml version="1.0" encoding="utf-8"?>
      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">
      <!-- android:paddingStart="?listPreferredItemPaddingLeft"
      android:paddingTop="@dimen/padding_list_row"
      android:paddingEnd="?listPreferredItemPaddingRight"
      android:paddingBottom="@dimen/padding_list_row"-->

      <RelativeLayout
      android:id="@+id/view_background"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/mailSwipeMenu">

      <LinearLayout
      android:id="@+id/right_swipe_options_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:gravity="center"
      android:orientation="horizontal"
      android:visibility="gone">

      <RelativeLayout
      android:id="@+id/unread_btn_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="@dimen/padding_10"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center">

      <ImageView
      android:id="@+id/mark_unread_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_read_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/mark_unread_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/mark_as_unread"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/spam_btn_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="@dimen/padding_10"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center">

      <ImageView
      android:id="@+id/report_spam_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_spam_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/report_spam_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/report_spam"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/move_btn_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginStart="@dimen/padding_10"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center">

      <ImageView
      android:id="@+id/move_mail_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_move_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/move_mail_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/move_mail"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>


      </LinearLayout>

      <RelativeLayout
      android:id="@+id/left_swipe_options_layout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentEnd="true"
      android:layout_centerVertical="true"
      android:layout_marginEnd="@dimen/padding_10"
      android:gravity="center"
      android:visibility="gone">

      <ImageView
      android:id="@+id/delete_icon"
      android:layout_width="@dimen/icon_delete"
      android:layout_height="@dimen/icon_delete"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="@dimen/padding_6"
      android:src="@drawable/icon_delete_button" />

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@id/delete_icon"
      android:layout_centerHorizontal="true"
      android:text="@string/delete"
      android:textColor="#fff"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/view_foreground"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/bg_list_row_inbox"
      android:orientation="vertical"
      android:padding="@dimen/padding_10">

      <LinearLayout
      android:id="@+id/message_container"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingStart="72dp"
      android:paddingEnd="@dimen/padding_list_row">

      <TextView
      android:id="@+id/from"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:lines="1"
      android:textColor="@color/from"
      android:textSize="@dimen/msg_text_primary"
      android:textStyle="bold" />

      <TextView
      android:id="@+id/txt_primary"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:lines="1"
      android:textColor="@color/subject"
      android:textSize="@dimen/msg_text_secondary"
      android:textStyle="bold" />

      <TextView
      android:id="@+id/txt_secondary"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ellipsize="end"
      android:lines="1"
      android:textColor="@color/message"
      android:textSize="@dimen/msg_text_secondary" />

      </LinearLayout>

      <RelativeLayout
      android:id="@+id/select_icon_container"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:orientation="vertical">

      <RelativeLayout
      android:id="@+id/icon_back"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <ImageView
      android:layout_width="@dimen/icon_width_height"
      android:layout_height="@dimen/icon_width_height"
      android:src="@drawable/bg_circle" />

      <ImageView
      android:layout_width="25dp"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      app:srcCompat="@drawable/icon_check_white_24dp" />

      </RelativeLayout>

      <RelativeLayout
      android:id="@+id/icon_front"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <ImageView
      android:id="@+id/icon_profile"
      android:layout_width="@dimen/icon_width_height"
      android:layout_height="@dimen/icon_width_height" />

      <TextView
      android:id="@+id/icon_text"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:textColor="@android:color/white"
      android:textSize="@dimen/text_icon" />
      </RelativeLayout>

      </RelativeLayout>

      <TextView
      android:id="@+id/timestamp"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentEnd="true"
      android:textColor="@color/timestamp"
      android:textSize="@dimen/text_timestamp"
      android:textStyle="bold" />

      <ImageView
      android:id="@+id/icon_star"
      android:layout_width="@dimen/icon_star"
      android:layout_height="@dimen/icon_star"
      android:layout_alignParentEnd="true"
      android:layout_alignParentBottom="true"
      android:tint="@color/icon_tint_normal" />

      </RelativeLayout>

      </FrameLayout>


      RecyclerItemTouchHelper.kt



       open class RecyclerItemTouchHelper(dragDirs: Int, swipeDirs: Int, private val listener: RecyclerItemTouchHelperListener) : ItemTouchHelper.SimpleCallback(dragDirs, swipeDirs) 

      override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean
      return true


      override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int)
      if (viewHolder != null)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

      getDefaultUIUtil().onSelected(foregroundView)



      override fun onChildDrawOver(c: Canvas, recyclerView: RecyclerView,
      viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
      actionState: Int, isCurrentlyActive: Boolean)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
      getDefaultUIUtil().onDrawOver(c, recyclerView, foregroundView, dX, dY,
      actionState, isCurrentlyActive)


      override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground
      getDefaultUIUtil().clearView(foregroundView)
      listener.onForegroundViewRestored(viewHolder,viewHolder.adapterPosition)


      override fun onChildDraw(c: Canvas, recyclerView: RecyclerView,
      viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float,
      actionState: Int, isCurrentlyActive: Boolean)
      val foregroundView = (viewHolder as InboxListAdapter.InboxItemHolder).viewForeground

      listener.onSwipeStart(viewHolder, if (dX < 0) ItemTouchHelper.LEFT else ItemTouchHelper.RIGHT, viewHolder.adapterPosition)
      getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX * .9F, dY,
      actionState, isCurrentlyActive)


      override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int)
      listener.onSwiped(viewHolder, direction, viewHolder.adapterPosition)


      override fun convertToAbsoluteDirection(flags: Int, layoutDirection: Int): Int
      return super.convertToAbsoluteDirection(flags, layoutDirection)




      interface RecyclerItemTouchHelperListener
      fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
      fun onSwipeStart(viewHolder: RecyclerView.ViewHolder, direction: Int, position: Int)
      fun onForegroundViewRestored(viewHolder: RecyclerView.ViewHolder, position: Int)




      InboxListAdapter.kt



      class InboxListAdapter() : RecyclerView.Adapter<InboxListAdapter.InboxItemHolder>() 


      var mContext: Context? = null
      private var messages = mutableListOf<InboxItemModel>()
      var listener: MessageAdapterListener? = null
      private var selectedItems: SparseBooleanArray? = null
      private var animationItemsIndex: SparseBooleanArray? = null
      private var reverseAllAnimations = false
      private var currentSelectedIndex = -1

      constructor(context: Context, messages: MutableList<InboxItemModel>, listener: MessageAdapterListener) : this()
      this.mContext = context
      this.messages = messages
      this.listener = listener
      selectedItems = SparseBooleanArray()
      animationItemsIndex = SparseBooleanArray()


      inner class InboxItemHolder(view: View) : RecyclerView.ViewHolder(view), View.OnLongClickListener ,View.OnClickListener
      var viewForeground : RelativeLayout = view.findViewById<View>(R.id.view_foreground) as RelativeLayout
      var viewBackGround : RelativeLayout = view.findViewById<View>(R.id.view_background) as RelativeLayout
      var viewLeftSwipe : RelativeLayout = view.findViewById<View>(R.id.left_swipe_options_layout) as RelativeLayout
      var viewRightSwipe : LinearLayout = view.findViewById<View>(R.id.right_swipe_options_layout) as LinearLayout
      var spamButtonLayout : RelativeLayout = view.findViewById<View>(R.id.spam_btn_layout) as RelativeLayout
      var moveButtonLayout : RelativeLayout = view.findViewById<View>(R.id.move_btn_layout) as RelativeLayout
      var unreadButtonLayout : RelativeLayout = view.findViewById<View>(R.id.unread_btn_layout) as RelativeLayout
      var deleteImageView : ImageView = view.findViewById<View>(R.id.delete_icon) as ImageView
      var from: TextView = view.findViewById<View>(R.id.from) as TextView
      var subject: TextView = view.findViewById<View>(R.id.txt_primary) as TextView
      var message: TextView = view.findViewById<View>(R.id.txt_secondary) as TextView
      var iconText: TextView = view.findViewById<View>(R.id.icon_text) as TextView
      var timestamp: TextView = view.findViewById<View>(R.id.timestamp) as TextView
      var iconImp: ImageView = view.findViewById<View>(R.id.icon_star) as ImageView
      var imgProfile: ImageView = view.findViewById<View>(R.id.icon_profile) as ImageView
      var messageContainer: LinearLayout = view.findViewById<View>(R.id.message_container) as LinearLayout
      var iconContainer: RelativeLayout = view.findViewById<View>(R.id.select_icon_container) as RelativeLayout
      var iconBack: RelativeLayout = view.findViewById<View>(R.id.icon_back) as RelativeLayout
      var iconFront: RelativeLayout = view.findViewById<View>(R.id.icon_front) as RelativeLayout

      init
      view.setOnLongClickListener(this)
      spamButtonLayout.setOnClickListener(this)
      moveButtonLayout.setOnClickListener(this)
      unreadButtonLayout.setOnClickListener(this)
      viewLeftSwipe.setOnClickListener(this)
      deleteImageView.setOnClickListener(this)



      override fun onLongClick(view: View): Boolean
      listener!!.onRowLongClicked(adapterPosition)
      view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
      return true


      override fun onClick(p0: View?)
      when(p0!!.id)
      R.id.spam_btn_layout -> listener!!.onSpamButtonClicked(adapterPosition)
      R.id.unread_btn_layout -> listener!!.onReadButtonClicked(adapterPosition)
      R.id.move_btn_layout -> listener!!.onMoveButtonClicked(adapterPosition)
      R.id.left_swipe_options_layout -> listener!!.onDeleteButtonClicked(adapterPosition)
      R.id.delete_icon -> listener!!.onDeleteButtonClicked(adapterPosition)





      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InboxItemHolder
      val itemView = LayoutInflater.from(parent.context)
      .inflate(R.layout.list_row_inbox, parent, false)

      return InboxItemHolder(itemView)


      override fun onBindViewHolder(holder: InboxItemHolder, position: Int)
      val message = messages[position]

      holder.from.text = message.sender
      holder.subject.text = message.subject
      holder.message.text = message.subject
      holder.timestamp.text = message.timeStamp
      holder.itemView.isActivated = selectedItems!!.get(position, false)


      [![enter image description here][1]][1]
      // apply click events
      applyClickEvents(holder, position)


      private fun applyClickEvents(holder: InboxItemHolder, position: Int)
      holder.iconContainer.setOnClickListener listener!!.onIconClicked(position)

      holder.iconImp.setOnClickListener listener!!.onIconImportantClicked(position)

      holder.messageContainer.setOnClickListener listener!!.onMessageRowClicked(position)

      holder.messageContainer.setOnLongClickListener view ->
      listener!!.onRowLongClicked(position)
      view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
      true





      Swiping the foreground layout



      enter image description here







      android android-recyclerview kotlin framelayout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 6:20









      Ashish singhAshish singh

      168




      168






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294194%2fhow-to-pass-click-events-to-overlapping-views-in-framelayout%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294194%2fhow-to-pass-click-events-to-overlapping-views-in-framelayout%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto