This is the answer to your now modified question:
@Override
public boolean canScrollHorizontally(int direction)
{
final int offset = computeHorizontalScrollOffset();
final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
if(range == 0){
return false;
}
return (direction < 0) ? (offset > 0) : (offset < range - 1);
}
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
left .setVisibility(canScrollHorizontally(-1) ? View.VISIBLE : View.GONE);
right.setVisibility(canScrollHorizontally( 1) ? View.VISIBLE : View.GONE);
}
I would recommend Drawables over using Views'.
So, I've extended HorizontalScrollView
and overridden the draw()
method to draw its own Drawable
's to the canvas
for the indicators. The rest of it is simply managing the position of them using setBounds
, and now a pressed state.
Code: https://gist.github.com/slightfoot/4c017f776663bf6dd5d8#file-indicatedhorizontalscrollview-java