Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/util/ViewUtils.kt
- This file was added.
| package it.reyboz.bustorino.util | |||||
| import android.graphics.Rect | |||||
| import android.util.Log | |||||
| import android.view.View | |||||
| import androidx.core.widget.NestedScrollView | |||||
| class ViewUtils { | |||||
| companion object{ | |||||
| const val DEBUG_TAG="BusTO:ViewUtils" | |||||
| fun isViewFullyVisibleInScroll(view: View, scrollView: NestedScrollView): Boolean { | |||||
| val scrollBounds = Rect() | |||||
| scrollView.getDrawingRect(scrollBounds) | |||||
| val top = view.y | |||||
| val bottom = top + view.height | |||||
| Log.d(DEBUG_TAG, "Scroll bounds are $scrollBounds, top:${view.y}, bottom $bottom") | |||||
| return (scrollBounds.top < top && scrollBounds.bottom > bottom) | |||||
| } | |||||
| fun isViewPartiallyVisibleInScroll(view: View, scrollView: NestedScrollView): Boolean{ | |||||
| val scrollBounds = Rect() | |||||
| scrollView.getHitRect(scrollBounds) | |||||
| Log.d(DEBUG_TAG, "Scroll bounds are $scrollBounds") | |||||
| if (view.getLocalVisibleRect(scrollBounds)) { | |||||
| return true | |||||
| } else { | |||||
| return false | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| No newline at end of file | |||||
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register