80,359
社区成员
发帖
与我相关
我的任务
分享
<SPAN style="FONT-FAMILY: Microsoft YaHei; FONT-SIZE: 18px"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="2000dip"
android:text="text" />
</LinearLayout>
</ScrollView>
</RelativeLayout></SPAN>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="2000dip"
android:text="text" />
</LinearLayout>
</ScrollView>
</RelativeLayout>[java] view plaincopyprint?
<SPAN style="FONT-FAMILY: Microsoft YaHei; FONT-SIZE: 18px">public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ScrollView view = (ScrollView) findViewById(R.id.scroll_view);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
if (v.getScrollY() <= 0) {
Log.d("scroll view", "top");
} else if (view.getChildAt(0).getMeasuredHeight() <= v.getHeight() + v.getScrollY()) {
Log.d("scroll view", "bottom");
Log.d("scroll view", "view.getMeasuredHeight() = " + view.getMeasuredHeight()
+ ", v.getHeight() = " + v.getHeight()
+ ", v.getScrollY() = " + v.getScrollY()
+ ", view.getChildAt(0).getMeasuredHeight() = " + view.getChildAt(0).getMeasuredHeight());
}
break;
default:
break;
}
return false;
} });
}
}</SPAN>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ScrollView view = (ScrollView) findViewById(R.id.scroll_view);
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
if (v.getScrollY() <= 0) {
Log.d("scroll view", "top");
} else if (view.getChildAt(0).getMeasuredHeight() <= v.getHeight() + v.getScrollY()) {
Log.d("scroll view", "bottom");
Log.d("scroll view", "view.getMeasuredHeight() = " + view.getMeasuredHeight()
+ ", v.getHeight() = " + v.getHeight()
+ ", v.getScrollY() = " + v.getScrollY()
+ ", view.getChildAt(0).getMeasuredHeight() = " + view.getChildAt(0).getMeasuredHeight());
}
break;
default:
break;
}
return false;
} });
}
}
view.getMeasuredHeight() = 1038
v.getHeight() = 1038
v.getScrollY() = 2962
view.getChildAt(0).getMeasuredHeight() = 4000