簡體   English   中英

Android Scrollview:如何檢測scrollview的開始和結束

[英]Android Scrollview : How to detect begin and end of scrollview

這是我的布局XML。 我要在表中動態添加更多行。

<?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實現分頁。 如果用戶嘗試向后或向前滾動,則我要發出上一頁和下一頁的請求。 怎么做? 任何提示將不勝感激。 謝謝。

這是解決該問題的骯臟方法

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幾乎是在末尾還是在開始時才行動。 這不是干凈的,而是使其工作的一種方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM