2010-12-11 71 views
0

這是我的佈局XML。我在表中動態添加更多行。Android ScrollView:如何檢測滾動視圖的開始和結束

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:myapp="http://schemas.android.com/apk/res/com.tweets" 
      android:id="@+id/screen" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:background="#FFFFFF"> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/main" 
       android:background="#FFFFFF"> 

     <TableRow android:id="@+id/TableRow01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 

      <TextView android:id="@+id/TLocView01" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="15px" 
         android:textStyle="bold" 
         android:textColor="#000000" 
         android:text="FatWallet Tweets:"> 
      </TextView> 

     </TableRow> 
    </TableLayout> 
</ScrollView> 

我想用scrollview實現分頁。如果用戶試圖向後或向前滾動,那麼我想做出上一頁和下一頁的請求。怎麼做?任何暗示將不勝感激。謝謝。

回答

0

這裏是解決這個問題

tl = (TableLayout) findViewById(R.id.main); 

    tl.setOnTouchListener(new OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 
      int y = v.getHeight(); 
      int y1 = (int) event.getY(); 

      switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: { 
       if (y1 + 50 >= y & more) { 
        //System.out.println("ACTION_DOWN " + bpg); 
        more(); 

       } 
       break; 
      } 

      case MotionEvent.ACTION_UP: { 
       if (y1 - 50 <= 100 & bpg > 1) { 
        //System.out.println("ACTION_UP"); 
        less(); 

       } 
       break; 
      } 
      case MotionEvent.ACTION_MOVE: { 
       //System.out.println("ACTION_MOVE " + bpg); 
       if (y1 - 50 <= 100 & bpg > 1) { 
        //System.out.println("ACTION_UP"); 
        less(); 

       } 
       break; 
      } 
      } 

      //System.out.println("Test " + y + " " + y1); 
      return true; 
     } 
    }); 

ACTION_DOWN事件正在處理一個頁面,並ACTION_MOVE事件處理上一頁一個骯髒的方式。我正在檢查當前的Y幾乎是在結束還是在開始時才行動。它不是乾淨的,而是使其工作的一種方式。

相關問題