Question

I have a HorizontalScrollView I want to scroll it towards left and Right on Button click. I have refered this post Here

But I'm not able to scroll it toward the left.As here getScrollX() gives the leftEdge of View.

So my Question is How could I make it scroll towards the left Side of View on btnClick.

Any Answer is Highly Appreciated..Thks

Was it helpful?

Solution

This code may help you ::

rightBtn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        hsv.scrollTo((int)hsv.getScrollX() + 10, (int)hsv.getScrollY());
    }
});

OTHER TIPS

Try

public void scrollToLeft(){
    horizontalScrollView.smoothScrollTo(horizontalScrollView.getScrollX() - 50, 0);
}

Just try this code. it works.

declare first

HorizontalScrollView hr;

then inside on create

hr=(HorizontalScrollView)findViewById(R.id.horizontal1);

and inside onclick of button , enter this code.

hr.fullScroll(HorizontalScrollView.FOCUS_LEFT);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top