Guest User

Untitled

a guest
Apr 24th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. How to disable a scrollView?
  2. scrollView.setEnable(false);
  3.  
  4. scrollView.setOnTouchListener(null);
  5.  
  6. scrollView.requestDisallowInterceptTouchEvent(true);
  7.  
  8. <ScrollView
  9. android:id="@+id/mainPage_scroll"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:layout_alignParentBottom="true"
  13. android:layout_alignParentLeft="true"
  14. android:layout_alignParentRight="true"
  15. android:focusableInTouchMode="true"
  16. android:layout_below="@+id/tabBar" >
  17.  
  18. </ScrollView>
  19.  
  20. //removed an invalid option/answer
  21.  
  22. scrollView.setVisibility(Visibility.GONE);
  23.  
  24. class LockableScrollView extends ScrollView {
  25.  
  26. ...
  27.  
  28. // true if we can scroll (not locked)
  29. // false if we cannot scroll (locked)
  30. private boolean mScrollable = true;
  31.  
  32. public void setIsScrollable(boolean scrollable) {
  33. mScrollable = scrollable;
  34. }
  35. public boolean getIsScrollable()
  36. return mScrollable;
  37. }
  38.  
  39. @Override
  40. public boolean onTouchEvent(MotionEvent ev) {
  41. switch (ev.getAction()) {
  42. case MotionEvent.ACTION_DOWN:
  43. // if we can scroll pass the event to the superclass
  44. if (mScrollable) return super.onTouchEvent(ev);
  45. // only continue to handle the touch event if scrolling enabled
  46. return mScrollable; // mScrollable is always false at this point
  47. default:
  48. return super.onTouchEvent(ev);
  49. }
  50. }
  51. }
  52.  
  53. <com.mypackagename.LockableScrollView
  54. android:id="@+id/QuranGalleryScrollView"
  55. android:layout_height="fill_parent"
  56. android:layout_width="fill_parent">
  57.  
  58. <Gallery android:id="@+id/Gallery"
  59. android:layout_width="fill_parent"
  60. android:layout_height="fill_parent"
  61. android:scrollbars="horizontal">
  62. </Gallery>
  63.  
  64. </com.mypackagename.LockableScrollView>
  65.  
  66. ((LockableScrollView)findViewById(R.id.QuranGalleryScrollView)).setIsScrollable(false);
Advertisement
Add Comment
Please, Sign In to add comment