The imageView start_messaging is not clickable after the searchList visibility is made GONE from VISIBLE even though only the first item in recyclerView is clickable in that fragment but not this button. However the button is clickable before the searchList was visible. You may preview the video for better clarification.
Video: https://youtube.com/shorts/MT9cMwZ5qdg?si=T7ERP5oFaojZDA-I
activity_dashboard.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_background_color"
tools:context=".activities.DashboardActivity">
<FrameLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/bottomNav">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/_5sdp"
android:layout_marginTop="@dimen/_3sdp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/toolbar_constraint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/currentTab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/alata"
android:text="@string/recent_chats"
android:textColor="@color/app_font_theme_color"
android:textSize="@dimen/_16ssp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/searchUsers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/search" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/searchBar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/toolbar_constraint">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_input_field"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/search_view_background"
app:iconifiedByDefault="false"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:queryHint="Username or phone num" />
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:id="@+id/callStatusHome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/searchBar_layout"
android:background="@color/app_component_color"
android:fontFamily="@font/alata">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Call Ongoing"
android:textColor="@color/white"
android:textSize="@dimen/_11ssp"
android:textAlignment="center"
android:fontFamily="@font/alata"
/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/searchList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
android:background="@color/red"
tools:listitem="@layout/chat_face"
android:elevation="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/callStatusHome"/>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/callStatusHome"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<ProgressBar
android:id="@+id/progress_circular"
android:layout_width="@dimen/_50sdp"
android:layout_height="@dimen/_50sdp"
android:indeterminate="true"
android:visibility="gone"
android:indeterminateTint="@color/app_component_color"
android:layout_gravity="center"/>
</FrameLayout>
<com.etebarian.meowbottomnavigation.MeowBottomNavigation
android:id="@+id/bottomNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mbn_circleColor="#ffffff"
app:mbn_backgroundBottomColor="@color/white"
app:mbn_countBackgroundColor="#ff6f00"
app:mbn_countTextColor="#ffffff"
app:mbn_defaultIconColor="#90a4ae"
app:mbn_rippleColor="#2f424242"
app:mbn_selectedIconColor="#075864"
app:layout_constraintBottom_toBottomOf="parent"
app:mbn_shadowColor="#1f212121"/>
<!-- <Button-->
<!-- android:id="@+id/signOut"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="Sign Out"-->
<!-- android:textAllCaps="false"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- />-->
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_chat.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/c1"
android:background="@color/app_background_color"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragments.ChatFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/c2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="@dimen/_3sdp">
<ProgressBar
android:id="@+id/progress_circular"
android:layout_width="@dimen/_50sdp"
android:layout_height="@dimen/_50sdp"
android:indeterminate="true"
android:visibility="gone"
android:indeterminateTint="@color/app_component_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/recentChatsRecycler"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recentChatsRecycler"
android:layout_width="match_parent"
android:layout_height="0dp"
app:stackFromEnd="true"
app:reverseLayout="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:itemCount="15"
tools:listitem="@layout/chat_face"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
<ImageView
android:id="@+id/start_messaging"
android:layout_width="@dimen/_50sdp"
android:layout_height="@dimen/_50sdp"
android:src="@drawable/start_messaging_icon"
android:elevation="@dimen/_10sdp"
android:layout_marginBottom="@dimen/_20sdp"
android:layout_marginRight="@dimen/_15sdp"
app:layout_constraintBottom_toBottomOf="@+id/recentChatsRecycler"
app:layout_constraintEnd_toEndOf="@+id/recentChatsRecycler" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
CODE
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDashboardBinding.inflate(layoutInflater)
binding.searchUsers.setOnClickListener {
if (!checkSearchCLickState){
checkSearchCLickState = true
Log.d("special1", "onCreate: Clicked")
fetchAllUsers()
showSearchPanel()
}else{
checkSearchCLickState = false
hideSearchPanel()
}
}
}
private fun showSearchPanel(){
val scaleAnim = ScaleAnimation(
1f, 1f,
0f, 1f,
Animation.ABSOLUTE, 1f,
Animation.RELATIVE_TO_SELF, 0f
)
scaleAnim.duration = 200
scaleAnim.repeatCount = 0
scaleAnim.interpolator = AccelerateDecelerateInterpolator()
scaleAnim.fillAfter = true
scaleAnim.fillBefore = true
scaleAnim.isFillEnabled = true
scaleAnim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(p0: Animation?) {
binding.searchList.visibility = View.VISIBLE
binding.searchBarLayout.visibility = View.VISIBLE
//binding.frame.visibility = View.GONE
binding.frame.fadeVisibility(View.GONE, 300)
}
override fun onAnimationEnd(p0: Animation?) {
}
override fun onAnimationRepeat(p0: Animation?) {
}
})
binding.searchBarLayout.startAnimation(scaleAnim)
binding.searchList.startAnimation(scaleAnim)
binding.searchUsers.setImageDrawable(resources.getDrawable(R.drawable.close_icon))
}
private fun hideSearchPanel(){
val scaleAnim = ScaleAnimation(
1f, 1f,
1f, 0f,
Animation.ABSOLUTE, 1f,
Animation.RELATIVE_TO_SELF, 0f
)
scaleAnim.duration = 200
scaleAnim.repeatCount = 0
scaleAnim.interpolator = AccelerateDecelerateInterpolator()
scaleAnim.fillAfter = true
scaleAnim.fillBefore = true
scaleAnim.isFillEnabled = true
scaleAnim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(p0: Animation?) {
}
override fun onAnimationEnd(p0: Animation?) {
binding.searchList.visibility = View.GONE
binding.searchBarLayout.visibility = View.GONE
binding.frame.fadeVisibility(View.VISIBLE, 300)
}
override fun onAnimationRepeat(p0: Animation?) {
}
})
binding.searchBarLayout.startAnimation(scaleAnim)
binding.searchList.startAnimation(scaleAnim)
binding.searchUsers.setImageDrawable(resources.getDrawable(R.drawable.search))
}
fun View.fadeVisibility(visibility: Int, duration: Long = 400) {
val transition: Transition = Fade()
transition.duration = duration
transition.addTarget(this)
TransitionManager.beginDelayedTransition(this.parent as ViewGroup, transition)
this.visibility = visibility
}
I am trying to figure out why it's not clickable as there is nothing above that imageView. I am expecting a clear explanation of this behavior.
android:elevation="@dimen/_10sdp"
This line was causing the problem, I just removed the elevation from the searchList and now no touch problem.