简体   繁体   English

Android Scrollview:如何检测scrollview的开始和结束

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

Here is my layout XML. 这是我的布局XML。 I am adding more rows in a table dynamically. 我要在表中动态添加更多行。

<?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>

I want to implement paging with scrollview. 我想用scrollview实现分页。 If user tries to scroll backward or forward then i want to make previous page and next page requests. 如果用户尝试向后或向前滚动,则我要发出上一页和下一页的请求。 How to do that? 怎么做? Any hint will be appreciated. 任何提示将不胜感激。 Thanks. 谢谢。

Here is a dirty way to solve that problem 这是解决该问题的肮脏方法

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 event is handling next page and ACTION_MOVE event is handling previous page. ACTION_DOWN事件正在处理下一页,而ACTION_MOVE事件正在处理上一页。 I am checking whether current Y is almost at the end or at the beginning then only act. 我正在检查当前Y几乎是在末尾还是在开始时才行动。 It is not clean but one way to make it work. 这不是干净的,而是使其工作的一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM