hi, i am a new android developer, and recently I was doing a horizontal scrolling menu. the follow is xml doc:
<com.kingkong.gallery.GalleryHorizontalView android:id="@+id/HorizontalScrollView01" android:layout_width="fill_parent" android:scrollbars="none" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/ourlayout" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> </LinearLayout> </com.kingkong.gallery.GalleryHorizontalView> class GalleryHorizontalView is defined by myself, it is extends from HorizontalScrollView. in GalleryHorizontalView, I made the following changes ( changes in method onTouchEvent(MotionEvent ev) ): case MotionEvent.ACTION_MOVE: // x == ev.getX(); final int deltaX = (int) (mLastMotionX - x); mLastMotionX = x; // i want to let the child view's ( LinearLayout ) horizontal padding change,so change //the child view's x coordinate, x coordinate is change by deltaX; if (deltaX < 0) { if (getScrollX() >= 0) { getChildAt(0).scrollBy(deltaX, 0); } } else if (deltaX > 0) { final int rightEdge = getWidth() - getPaddingRight(); final int availableToScroll = getChildAt(0).getRight() - getScrollX() - rightEdge; if (availableToScroll > 0) { getChildAt(0).scrollBy(Math.min(availableToScroll, deltaX), 0); } } break; case MotionEvent.ACTION_UP: int menuItemWidth = 80; int temp = getChildAt(0).getScrollX(); int remainder = temp %menuItemWidth; int scrollToCoords = 0; // if temp <0 or temp == the child view's left coordinate, scrollToCoords =0; //scrollToCoords's value is x coordinate when the child view end its scrolling. //the follow calculation is to ensure that each option can be displayed properly if (temp < 0 || temp == getChildAt(0).getLeft()) { scrollToCoords = 0; } else if (temp >= getChildAt(0).getRight() / 2) { scrollToCoords = getChildAt(0).getWidth() / 2; } else if (temp < getChildAt(0).getRight() && temp > getChildAt(0).getLeft()) { if (remainder == 0) { scrollToCoords = temp; } else { if (remainder > menuItemWidth/2) { scrollToCoords = temp - remainder + menuItemWidth; } if (remainder <= menuItemWidth/2) { scrollToCoords = temp - remainder; } } } float mDeltaX = mLastMotionX - x; mScroller.startScroll((int)mLastMotionX, 0, (int)x, 0, 1000); this.invalidate(); getChildAt(0).scrollBy((int) mDeltaX, 0); getChildAt(0).scrollTo(scrollToCoords, 0); i run my app after made this change,the child view LinearLayout can scroll with the order, but it looks like jump, not smooth scrolling, how can make the scroll smooth. thanks very much. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---