Scroll horizontalScrollView left-right

人盡茶涼 提交于 2019-12-13 07:56:42

问题


I'm using HorizontalScrollView for show header in my app,I also need to scroll header left-right on clicking on left-right button.I have used some code that is working successfully in scrolling right-to-left but i'm unable to scroll left-to-right.please suggest me how to solve this

My code for scroll right-to-left

    horiScrollView.scrollBy(20, 20);

please suggest me how to solve this problem.Thanks


回答1:


Make the first number negative. the right number doesn't do anything (it's vertical change). First number is how much to move horizontally - so positive numbers mean go right, negative numbers mean go left.




回答2:


I had exactly the same problem - I have a button of language and by that the horiScrollView sliding is set.

I do that with a new class that extends horizontalScrollView, and there in the onMesuare method I set the side by calling horiScrollView.scrollBy(20, 20), like you did.

In this method, I check if the language is changed, and if so, scroll to the right position I want. This is the only method I found and it works perfectly.

In that way I also separated the horizontalScrollView code from the entire screen, the horizontalScrollView in my app in controlling all the screen, so I prefer to make a distinction between the activity and the horizontalScrollView.




回答3:


This code work well for me:

mHorScrollView.post(new Runnable() {

        @Override
        public void run() {
            if (rightButton) {
                mHorScrollView.smoothScrollTo(20, 0);
            } else {
                mHorScrollView.smoothScrollTo(-20, 0);
            }
        }
    });


来源:https://stackoverflow.com/questions/12842915/scroll-horizontalscrollview-left-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!