Android自定义View缓冲,android : 自定义无上下缓冲色的ScrollView 类名称:NoFadingScrollView...

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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值