import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.widget.ListView;
/**
* Created by user on 26/7/2017.
*/
public class MyListView extends ListView {
private static final int MAX_Y_OVERSCROLL_DISTANCE = 200;//可滑動范圍
private Context mContext;
private int mMaxYOverscrollDistance;
public MyListView(Context context){
super(context);
mContext = context;
initBounceListView();
}
public MyListView(Context context, AttributeSet attrs){
super(context, attrs);
mContext = context;
initBounceListView();
}
public MyListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
mContext = context;
initBounceListView();
}
private void initBounceListView(){
//get the density of the screen and do some maths with it on the max overscroll distance
//variable so that you get similar behaviors no matter what the screen size
final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
final float density = metrics.density;
mMaxYOverscrollDistance = (int) (density * MAX_Y_OVERSCROLL_DISTANCE);
}
@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent){
//This is where the magic happens, we have replaced the incoming maxOverScrollY with our own custom variable mMaxYOverscrollDistance;
return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, mMaxYOverscrollDistance, isTouchEvent);
}
@Override
/**
* 重寫該方法卒废,ScrollView中嵌套ListView
* 達到使ListView自適應(yīng)高度
*/
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
阻尼回彈效果双妨,以及ScrollView嵌套listview導(dǎo)致顯示一行數(shù)據(jù)的問題
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門储矩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人褂乍,你說我怎么就攤上這事持隧。” “怎么了逃片?”我有些...
- 文/不壞的土叔 我叫張陵屡拨,是天一觀的道長。 經(jīng)常有香客問我褥实,道長呀狼,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任损离,我火速辦了婚禮哥艇,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘僻澎。我一直安慰自己她奥,他們只是感情好瓮增,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著哩俭,像睡著了一般。 火紅的嫁衣襯著肌膚如雪拳恋。 梳的紋絲不亂的頭發(fā)上凡资,一...
- 文/蒼蘭香墨 我猛地睜開眼轰驳,長吁一口氣:“原來是場噩夢啊……” “哼厚掷!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起级解,我...
- 正文 年R本政府宣布,位于F島的核電站映屋,受9級特大地震影響苟鸯,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜棚点,卻給世界環(huán)境...
- 文/蒙蒙 一早处、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧瘫析,春花似錦砌梆、人聲如沸默责。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽桃序。三九已至,卻和暖如春烂瘫,著一層夾襖步出監(jiān)牢的瞬間媒熊,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 背景 咣當咣當咣當愈犹,乘著北京的地鐵上班,突然倆小伙談話被我聽到了闻丑。"今天我遇到了一個很奇怪的問題漩怎,一個Scroll...
- 摘要:開發(fā)中經(jīng)常遇到ScrollView嵌套ListView,GridView,或者RecyclerView嵌套R...
- 關(guān)于為什么只顯示一行勋锤,個人理解是:如果單獨使用GridView和ListView,里面的內(nèi)容是固定的侥祭,底層系統(tǒng)很容...