Radwa Radwa - 5 months ago 19
Android Question

Android Scroll ScrollView automatically in onCreate method

I have some kinde of calendar and I use ScrollView to scroll to days
I want it on create it will be scroll able to today date
here is the cod I use:

scrollV.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
scr.post(new Runnable() {
public void run() {
scrollV.scrollTo(0,3); }
});
}
});


3 is just for test I'll change it later; thanks in advance.

Answer

I solved it here is the answer for any one need it : Just put a timer in OnCreate method or in onCreateView if it is a fragment

new java.util.Timer().schedule(
                new java.util.TimerTask() {
                    @Override
                    public void run() {
                        list.smoothScrollToPosition(day);
                    }
                },
                4000
        );

day is the variable you want to the list to scroll to it's day of month for me , list is the list view

Comments