The range of view in which the code below runs is small. Currently, it runs for the topmost part of a Fragment only.
The following is the code for setOnTouchListener:
val view = inflater.inflate(R.layout.fragment_main, container, false)
view.setOnTouchListener(View.OnTouchListener { view, motionEvent ->
if (motionEvent.action == MotionEvent.ACTION_UP){
texteffectskip = true
}
return@OnTouchListener true
})
activity_main.xml
<FrameLayout
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
fragment.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"
tools:context=".fragment_main"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/recyclerView"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="20dp">
<TextView
android:id="@+id/txt_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"/>
</ScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I want to run in the whole Fragment. I tried to adjust the height of the layout, but it wasn't helpful.
Any help is appreciated!
Currently, View has ScrollView and ReyclerView. I thought if i press ScrollView, View will be pressed. but That's not true. So I have to attach a TouchListener to the other view.
var scroller = view.findViewById(R.id.scroll_content) as ScrollView
scroller.setOnTouchListener(View.OnTouchListener { view, motionEvent ->
if (motionEvent.action == MotionEvent.ACTION_UP){
texteffectskip = true
}
return@OnTouchListener true
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.