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

有帮助吗?

解决方案

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());
    }
});

其他提示

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);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top