问题描述
下面是我的布局XML。我在一个表中动态地添加更多的行。
Here is my layout 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>
我要实现与滚动视图分页。如果用户试图向后滚动或转发,然后我要让previous和下一页的请求。怎么做?任何暗示将AP preciated。谢谢。
I want to implement paging with 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事件处理下一个页面,ACTION_MOVE事件处理previous页面。我检查当前y是否几乎是在年底或一开始那么只有行为。这是不干净的,但一种方法,使其工作。
ACTION_DOWN event is handling next page and ACTION_MOVE event is handling previous page. I am checking whether current Y is almost at the end or at the beginning then only act. It is not clean but one way to make it work.
这篇关于Android的滚动型:如何检测开始,滚动型的结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!