【发布时间】:2014-04-30 16:26:54
【问题描述】:
我有一个 HorizontalScrollView 的子类,我在其中添加多个图像。 我必须在屏幕的左右端显示某种指示器,以显示左右两侧是否有剩余物品。当我们到达相关终点时,相应的指示器也会消失。
谁能告诉我可用的选项?
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
View view = (View) takeparent().getChildAt(takeparent().getChildCount()-1); //this is the last view
int diff = (view.getRight()-(getRight()+getScrollX()));// Calculate the scrolldiff
if( diff == 0 ){ // if diff is zero, then the rightmost end has been reached
right.setVisibility(View.GONE); //setting the right button invisible
}
View viewleft = (View) takeparent().getChildAt(0); taking the first View
int diffleft2 = (viewleft.getLeft()-(getLeft()+getScrollX()));// Calculate the scrolldiff
if( diffleft2 == 0 ){ // if diff is zero, then the bottom has been reached
left.setVisibility(View.GONE);
}
super.onScrollChanged(l, t, oldl, oldt);
}
【问题讨论】:
标签: java android android-layout mobile horizontalscrollview