views:

50

answers:

2

Hello guys

I have created one custom view that contains the horizontalscrollview. Now when i changes the orientation its scroll state change to 0 every time.

I got the previous scroll state by using onSaveInstanceState(Bundle savedInstanceState) and onRestoreInstanceState(Bundle savedInstanceState) . in onRestoreInstanceState i am using following method to get reposition the scroll,

hoz_scroll.scrollTo(hoz_x_pos, hoz_scroll.getScrollY());

But there is not effect at all. Help appreciated. Thanks.

+1  A: 

I believe you need to set

android:configChanges="orientation"

in your activity's element in AndroidManifest.xml.

Then you need to override public void onConfigurationChanged(Configuration config) in your activity.

racetrack
I set the android:configChanges="orientation" but i am not getting into onConfigurationChanged...
sohilv
+2  A: 

If you have to call onCreate every time orientation change the position resets. You can avoid it by adding orientation changed to manifest but not sure if current scroll state is intact. I have researched it couple of days ago.If your interface has stadar dimentions on every orientation then you might find an equation by sampling many scroll values.

Create a map with the getScrollY() with values on landscape and portait that displays the same text. More values are better. Then use Polynomial interpolation to create a polynomial equation using matlab or papper. More values -> more accuracy http://en.wikipedia.org/wiki/Polynomial_interpolation

also scrolling to a position must be done like this

hoz_scroll.post(new Runnable() {

    public void run() {
        scroller.scrollTo(hoz_x_pos,hoz_scroll.getScrollY());
    }
});
weakwire
+1 Thanks! your code works. but why it didnt work without runnable, any idea ?
sohilv
because the scrollview is not allocated in the view yet.
weakwire