If I swipe left to right or right to left, then I swipe up or down without releasing finger swiping up or down occurred on Scroll Gesture. But I don't want to occur this. I want if am swiping horizontally only horizontal swiping should work not vertical without release finger. I don't know how doing that in android studio, If anyone can help, please help me, thanks in advance.
I have already tried, but can't solve the above problem.
override fun onScroll(event: MotionEvent?, event1: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
val sWidth = Resources.getSystem().displayMetrics.widthPixels
val sHeight = Resources.getSystem().displayMetrics.heightPixels
val border = 100 * Resources.getSystem().displayMetrics.density.toInt()
if(event!!.x < border || event.y < border || event.x > sWidth - border || event.y > sHeight - border)
return false
if(abs(distanceX) < abs(distanceY)){
if(event.x < sWidth/2){
//brightness
binding.brightnessIcon.visibility = View.VISIBLE
binding.volumeIcon.visibility = View.GONE
val increase = distanceY > 0
val newValue = if(increase) brightness + 1 else brightness - 1
if(newValue in 0..30) brightness = newValue
binding.brightnessIcon.text = brightness.toString()
setScreenBrightness(brightness)
}
else{
//volume
binding.brightnessIcon.visibility = View.GONE
binding.volumeIcon.visibility = View.VISIBLE
val maxVolume = audioManager!!.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
val increase = distanceY > 0
val newValue = if(increase) volume + 1 else volume - 1
if(newValue in 0..maxVolume) volume = newValue
binding.volumeIcon.text = volume.toString()
audioManager!!.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0)
}
}
return true
}
Check my answer for a question related to a RecyclerView in a ViewPager. This problem might be similar to yours.
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.