Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add effect bounce to listview in android</p> <p><strong>Step 1</strong>: Create new file BounceListView in package com.base.view</p> <pre><code>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); } } </code></pre> <p><strong>Step 2:</strong> At your layout, please change </p> <pre><code>&lt;ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; </code></pre> <p>to </p> <pre><code>&lt;com.base.view.BounceListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload