Android Scrollview: how to determine the beginning and end of scrollview

Here is my XML layout. I am adding more rows to the 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. If the user is trying to scroll back or forward, I want to make the previous pages and the next page requests. How to do it? Any hint would be appreciated. Thank you

0
android paging scrollview
Dec 11 '10 at 2:51
source share
1 answer

Here is a dirty way to solve this 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; } }); 

The ACTION_DOWN event processes the next page, and the ACTION_MOVE event processes the previous page. I check if the current Y is almost at the end or at the beginning, and then acts. This is not clean, but one way to make it work.

0
Dec 11 2018-10-12T00:
source share



All Articles