How to identify if a view is scrollable view in Android? -
How to identify if a view is scrollable view in Android? -
i creating custom view. need parse parents till scrollable view. how can identify view scrollable view ?
one simple way :
while(view != null){ if(view.getparent() instanceof view) { view = (view) view.getparent(); } else{ view = null; } if(view instanceof listview){ scrollableparentview = view; break; } else if(view instanceof scrollview){ scrollableparentview = view; break; } else if(view instanceof gridview){ scrollableparentview = view; break; } else if(view instanceof horizontalscrollview){ scrollableparentview = view; break; } }` with approach implementation fail if tomorrow new scrollable view android.
please suggest approach.
one more question : how can hear parent scrollview event in custom kid view?
thanks in advance.
to observe scrollable view can check if it's scrollable specific direction:
if (view.canscrollhorizontally(1)) { // scrollable right } else if (view.canscrollhorizontally(-1)) { // scrollable left } else if (view.canscrollvertically(1)) { // scrollable top } else if (view.canscrollvertically(-1)) { // scrollable bottom } else { // un-scrollable } android view android-custom-view
Comments
Post a Comment