2

Are there other ways to implement a Horizontal ListView in Android with bouncing/ recoil effect after it reaches the end of the list? I used this HorizontalListView. Then since i'm also implementing a bouncing effect in my ListView (vertical)..I used this:

 public class BounceListView extends ListView
 {
     private static final int MAX_Y_OVERSCROLL_DISTANCE = 100;

     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);  
    }

 }

So, what i thought was since this class was used to implement a recoil/bounce effect, why not modify this for my HorizontalListView..so i created a class similar to this but extended it to HorizontalListView then change instead of y to x. But it didn't work. One thing also, overScrollBy is not defined in AdapterView (since HorizontalListVIew extends to this.) Are there ways to implement a horizontal list with bounce? or are there open source libraries that could be of help? Any help is greatly appreciated.

4

1 回答 1

1

有一个简单的库旋转布局,允许将ListView旋转到水平方向(-90 度)。所有触摸事件都可以正常工作。此外,您必须将每个项目都转到 +90 度,但这也很简单。让 ListView 处于水平方向,您可以避免使用Horizo​​ntalListView

于 2014-08-04T14:27:04.933 回答