开发者

Is there any way to find the currently visible tabs in horizontalScrollVIew?

I have implemented a HorizontalScrollView in my TabWidgets to scroll tabs.How do i know which tabs are currently visible when user scroll the tabs?

Is there any way to find the current开发者_如何学JAVAly visible tabs? Thanks in advance..


It's quite difficult while there is no "tabls" in scroll views.


if you know the width of each tab (i'm assuming they are all same). you will know the starting and ending locations of each view.

using

HorizontalScrollView.getScrollX();

you will be able to calculate if a view is visible or not. since you will know the start and end points of horizontal scroll view as well.

based on your comment.

there is

HorizontalScrollView.getLeft()
HorizontalScrollView.getRight()

you can use them to find if the scroll view is full left or full right to toggle the arrows.

there is also an

hsv.getMaxScrollAmount()

which should be used to find the right end and the left should be 0 i guess.

UPDATE

i found this today.

View.willNotDraw()

your buttons in side the horizontal scroll view should have this method. check, if this helps. i guess this will tell if a view gets drawn or not.


I just solved this problem for me. Try implementing this at your PagerAdapter

class MyPagerAdapter extends PagerAdapter {
                      ...

    public void onPageSelected(int position) {          

        // This makes the TabHost scroll to certain x position 
        // determined by scrollPos
        View tabView = mTabHost.getChildAt(position);
        final int scrollPos = (int) (mTabHost.getWidth() * (position / (double) Math.pow(getCount(),2)));
        hScrollView.smoothScrollTo(scrollPos, 0);
    }
                             ...
}

Even if it worked for me the values for the scroll may be wrong. Hope it helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜