我試圖讓我的listview「反彈」。爲了解釋我自己,我希望ListView具有與iOs列表視圖對象相同的行爲。在列表的頂部和底部,用戶可以通過滑動手指來查看列表。在Android中創建彈出列表視圖
在Android 2.2三星設備(例如Galaxy Tab GT1000)上存在此行爲。
在我測試的大多數設備上,列表現在在滾動時表現不同,它顯示的藍線在您滑動手指時變得更亮。
我發現BounceListView像這樣的:
public class BounceListView extends ListView
{
private static final int MAX_Y_OVERSCROLL_DISTANCE = 200;
private Context mContext;
private int mMaxYOverscrollDistance;
public BounceListView(Context context)
{
super(context);
mContext = context;
initBounceListView();
}
public BounceListView(Context context, AttributeSet attrs)
{
super(context, attrs);
mContext = context;
initBounceListView();
}
public BounceListView(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);
}
}
但這ListView控件的問題是,它不會再回到第一個或最後一個項目滾動在列表之後...它停留在沒有填充列表的位置。
任何人有一個想法,使其工作?
在此先感謝!
我不認爲這是一個非常好的主意。違反OS慣例只會讓用戶感到困惑。在Android上,當您位於列表末尾時,您會看到一個彩色色調,讓您知道它們不再是項目。改變色調的顏色以適應你的應用的主題可能是一個更好的主意。 – Teovald