public class NoFadingScrollView extends ScrollView {
// private static final int MAX_Y_OVERSCROLL_DISTANCE =
65;
// private int mMaxYOverscrollDistance;
private ScrollViewInterface scrollViewInterface;
public NoFadingScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub.
initView();
// initBounceScrollView(context);
}
public NoFadingScrollView(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
initView();
// initBounceScrollView(context);
}
public NoFadingScrollView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
initView();
// initBounceScrollView(context);
}
@SuppressLint("NewApi")
private void initView() {
if (SdkVersion_U.hasGingerbread()) {
setOverScrollMode(View.OVER_SCROLL_NEVER);
} else {
setVerticalFadingEdgeEnabled(false);
}
}
// private void initBounceScrollView(Context mContext) {
// final DisplayMetrics metrics =
mContext.getResources()
// .getDisplayMetrics();
// final float density = metrics.density;
// mMaxYOverscrollDistance = (int) (density *
MAX_Y_OVERSCROLL_DISTANCE);
// }
// @TargetApi(Build.VERSION_CODES.GINGERBREAD)
// @Override
// protected boolean overScrollBy(int deltaX, int deltaY, int
scrollX,
// int scrollY, int scrollRangeX, int scrollRangeY,
// int maxOverScrollX, int maxOverScrollY, boolean
isTouchEvent) {
// return super.overScrollBy(deltaX, deltaY, scrollX,
scrollY,
// scrollRangeX, scrollRangeY, maxOverScrollX,
// mMaxYOverscrollDistance, isTouchEvent);
// }
public void setListViewHeightBasedOnChildren(ListView
listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
int count = listAdapter.getCount();
for (int i = 0; i < count; i++) {
View listItem = listAdapter.getView(i, null, listView);
// Log_U.Log_v("", "listItem=" + listItem);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params =
listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() -
1));
listView.setLayoutParams(params);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int
oldt) {
// TODO Auto-generated method stub
super.onScrollChanged(l, t, oldl, oldt);
if (getScrollY() + getHeight() >=
computeVerticalScrollRange()) {
// 滑到最下方
if (scrollViewInterface != null) {
scrollViewInterface.scrollBottom(true);
}
}else {
// 不在最下方
if (scrollViewInterface != null) {
scrollViewInterface.scrollBottom(false);
}
}
if (scrollViewInterface != null) {
scrollViewInterface.onScrollChanged(this, l, t, oldl, oldt);
}
}
@Override
public void scrollBy(int x, int y) {
// TODO Auto-generated method stub
super.scrollBy(x, y);
}
public ScrollViewInterface getScrollViewInterface() {
return scrollViewInterface;
}
public void setScrollViewInterface(ScrollViewInterface
scrollViewInterface) {
this.scrollViewInterface = scrollViewInterface;
}
public interface ScrollViewInterface {
public void scrollBottom(boolean isBottom);
public void onScrollChanged(ScrollView scrollView, int x, int
y, int oldx, int oldy);
}
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect
rect) {
//防止自动滚动
return 0;
}
}