[android-developers] Re: Scroller widget in a WebView

2009-04-30 Thread ironox

i have the same quesiton,help needed:)

thanks;

On 3月10日, 上午4时59分, oyobyaw  wrote:
> Hello,
>
> I am trying to implement a custom WebView and override OnTouchEvent()
> so that a tap near the bottom of the screen would result in the view
> smoothly scrolling down one 'page' (and a tap at the top would result
> in a smooth upward scroll).
>
> I've been looking at theScrollerWidget to do the animated scrolling
> but can't seem to figure out how to make it work right. I found an
> example of how to use aScrollerto animate a TextView (http://bear-
> polka.blogspot.com/2009/01/scrolltextview-scrolling-textview-
> for.html), but TextViews have a setScroller() method to attach aScrollerto 
> that view.
>
> How can you attach and use aScrollerin a View that does not expose a
> setScroller() method?
>
> Below is the relevant section of my code:
>
> privateScrollermScroller;
> private static final long TAP_THRESHHOLD = 300; //ms
> private float mDownY = 0;
> private int mHeight = 0;
> private int mWidth = 0;
>
> public MyWebView(Context context, ChapterNavigator cn) {
>super(context);
>mScroller = newScroller(context);
>
> }
>
> @Override
> public boolean onTouchEvent(MotionEvent event) {
>Log.v(TAG, "onTouchEvent");
>final int action = event.getAction();
>
>if (action == MotionEvent.ACTION_DOWN) {
>   //Abort scrolling animation if not finished yet
>   if (!mScroller.isFinished()) {
>  Log.v(TAG, "aborting scroll");
>  mScroller.abortAnimation();
>   }
>   mDownY = event.getY();
>}
>else if (action == MotionEvent.ACTION_UP) {
>   //Detect if we had a TAP
>   if(event.getEventTime() - event.getDownTime() < TAP_THRESHHOLD)
> {
>  if(event.getX() < mHeight/2 ) {
> mScroller.startScroll(0, mDownScrollY, 0, -mHeight, 1000);
>  }
>  else {
> mScroller.startScroll(0, mDownScrollY, 0, mHeight, 1000);
>  }
>   }
>}
>return true;
>
> }
>
> @Override
> protected void onSizeChanged(int w, int h, int ow, int oh) {
>super.onSizeChanged(w, h, ow, oh);
>mWidth = w;
>mHeight = h;
>
> }
>
> I'd greatly appreciate any pointer or suggestion.
>
> Thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Scroller widget in a WebView

2009-04-21 Thread Naseer

Hi,
Was anyone able to resolve this ? I have the same issue as well.
After startScroll, if I do getCurrX, I can see the new x value but the
view does not move. I think the view is not being attached to the
scroller.


Thanks,
-Naseer

On Mar 10, 1:59 am, oyobyaw  wrote:
> Hello,
>
> I am trying to implement a custom WebView and override OnTouchEvent()
> so that a tap near the bottom of the screen would result in the view
> smoothly scrolling down one ‘page’ (and a tap at the top would result
> in a smooth upward scroll).
>
> I’ve been looking at the Scroller Widget to do the animated scrolling
> but can’t seem to figure out how to make it work right. I found an
> example of how to use a Scroller to animate a TextView (http://bear-
> polka.blogspot.com/2009/01/scrolltextview-scrolling-textview-
> for.html), but TextViews have a setScroller() method to attach a
> Scroller to that view.
>
> How can you attach and use a Scroller in a View that does not expose a
> setScroller() method?
>
> Below is the relevant section of my code:
>
> private Scroller mScroller;
> private static final long TAP_THRESHHOLD = 300; //ms
> private float mDownY = 0;
> private int mHeight = 0;
> private int mWidth = 0;
>
> public MyWebView(Context context, ChapterNavigator cn) {
>    super(context);
>    mScroller = new Scroller(context);
>
> }
>
> @Override
> public boolean onTouchEvent(MotionEvent event) {
>    Log.v(TAG, "onTouchEvent");
>    final int action = event.getAction();
>
>    if (action == MotionEvent.ACTION_DOWN) {
>       //Abort scrolling animation if not finished yet
>       if (!mScroller.isFinished()) {
>          Log.v(TAG, "aborting scroll");
>          mScroller.abortAnimation();
>       }
>       mDownY = event.getY();
>    }
>    else if (action == MotionEvent.ACTION_UP) {
>       //Detect if we had a TAP
>       if(event.getEventTime() - event.getDownTime() < TAP_THRESHHOLD)
> {
>          if(event.getX() < mHeight/2 ) {
>             mScroller.startScroll(0, mDownScrollY, 0, -mHeight, 1000);
>          }
>          else {
>             mScroller.startScroll(0, mDownScrollY, 0, mHeight, 1000);
>          }
>       }
>    }
>    return true;
>
> }
>
> @Override
> protected void onSizeChanged(int w, int h, int ow, int oh) {
>    super.onSizeChanged(w, h, ow, oh);
>    mWidth = w;
>    mHeight = h;
>
> }
>
> I’d greatly appreciate any pointer or suggestion.
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---