标签:des android style blog io ar color os 使用
重写listview中overScrollBy()方法,修改maxOverScrollY为自己当前设定的值。
/**
*
* Description:仿ios ListView有弹力拉伸效果
*
* @author YangDODO
*
*/
public class FlexibleListView extends ListView {
private static int mMaxOverDistance = 50;// 拉伸距离
public FlexibleListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initView(context);
}
public FlexibleListView(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public FlexibleListView(Context context) {
super(context);
initView(context);
}
private void initView(Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float density = metrics.density;
mMaxOverDistance = (int) (density * mMaxOverDistance);
}
@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, mMaxOverDistance,
isTouchEvent);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }
/** * 设置listview高度,注意listview子项必须为LinearLayout才能调用该方法 * @param listview listview * */ public static void setListViewHeight(ListView listview){ int totalHeight = 0; ListAdapter adapter= listview.getAdapter(); if(null != adapter){ for (int i = 0; i <adapter.getCount(); i++) { View listItem = adapter.getView(i, null, listview); if (null != listItem) { listItem.measure(0, 0);//注意listview子项必须为LinearLayout才能调用该方法 totalHeight += listItem.getMeasuredHeight(); } } ViewGroup.LayoutParams params = listview.getLayoutParams(); params.height = totalHeight + (listview.getDividerHeight() * (listview.getCount() - 1)); listview.setLayoutParams(params); } }
标签:des android style blog io ar color os 使用
原文地址:http://www.cnblogs.com/rural/p/4158106.html