0
我有一個HorizontalScrollView的子類,我在其中添加多個圖像。 我必須在屏幕的左右兩側顯示某種指示符,以顯示左側和右側是否有剩餘物品。當我們達到相關目標時,各自的指標也應該消失。指標,當我們到達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);
}
請問您能解釋一下您的答案。我沒有得到你。 – user3265443
更新了答案 – Simon
對不起,但我仍然沒有得到你,因爲它沒有提到如何顯示和消失指標達到各自的目的。該指標讓我們假設是一個按鈕 – user3265443