Guest User

Untitled

a guest
May 6th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. ScrollView sliding from bottom to top, programmatically
  2. sv = (ScrollView)findViewById(R.id.scroll_text);
  3.  
  4. @Override
  5. public void onStart()
  6. {
  7. super.onStart();
  8. sv.post(new Runnable() {
  9.  
  10. @Override
  11. public void run() {
  12. sv.fullScroll(ScrollView.FOCUS_DOWN);
  13. }
  14. });
  15.  
  16. }
  17.  
  18. @Override
  19. public void onWindowFocusChanged(boolean hasFocus)
  20. {
  21. if (hasFocus)
  22. {
  23.  
  24. int display_h = display.getHeight();
  25. pos_y = display_h;
  26. mScrollHandler.removeCallbacks(mUpdateScroll);
  27. mScrollHandler.postDelayed(mUpdateScroll, 0);
  28.  
  29. }
  30. else
  31. {
  32.  
  33. mScrollHandler.removeCallbacks(mUpdateScroll);
  34.  
  35. }
  36. }
  37.  
  38. private Runnable mUpdateScroll = new Runnable() {
  39. public void run() {
  40. pos_y = pos_y - 1;
  41. sv.scrollTo(0, pos_y);
  42. mScrollHandler.postDelayed(mUpdateScroll, 100);
  43. }
  44. };
  45.  
  46. display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
  47. int display_h = display.getHeight();
  48. pos_y = display_h;
  49.  
  50. @Override
  51. public void onWindowFocusChanged(boolean hasFocus)
  52. {
  53. if (hasFocus)
  54. {
  55.  
  56. RelativeLayout r_main = (RelativeLayout)findViewById(R.id.RelativeTables);
  57. RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)r_main.getLayoutParams();
  58. params.leftMargin = 0;
  59. params.topMargin = pos_y;
  60. r_main.setLayoutParams(params);
  61. mScrollHandler.removeCallbacks(mUpdateScroll);
  62. mScrollHandler.postDelayed(mUpdateScroll, 0);
  63.  
  64. }
  65. else
  66. {
  67.  
  68. mScrollHandler.removeCallbacks(mUpdateScroll);
  69.  
  70. }
  71.  
  72. private Runnable mUpdateScroll = new Runnable() {
  73. public void run() {
  74. pos_y = pos_y - 1;
  75. RelativeLayout r_main = (RelativeLayout)findViewById(R.id.RelativeTables);
  76. RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)r_main.getLayoutParams();
  77. params.leftMargin = 0;
  78. params.topMargin = pos_y;
  79. r_main.setLayoutParams(params);
  80. mScrollHandler.postDelayed(mUpdateScroll, 100);
  81.  
  82. // the running cycle:
  83. if (pos_y<-display.getHeight()) {
  84. pos_y = display.getHeight();
  85. }
  86.  
  87. }
  88. };
Advertisement
Add Comment
Please, Sign In to add comment