回弹效果的RecyclerView仅支持线性的水平和竖直
废话不多少直接上代码:
一、Activity
package com.ahtelit.zbv.vphandler;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* Created by Administrator on 2018/6/6.
* qzx
* <p>
* RecyclerView---水平排布
* 具有顶部和底部可延伸一段距离,松开回弹的效果
*/
public class BounceRecyclerView extends RecyclerView {
private int oritation;
public int getOritation() {
return oritation;
}
/**
* 只能设置0和1
* <br/><br/>
* 0表示RecylerView是竖直排布
* <br/><br/>
* 1表示RecylerView是水平排布
* <br/><br/>
* 否则默认为0---竖直排布
*/
public void setOritation(int oritation) {
if (oritation != 0 && oritation != 1) {
oritation = 0;
}
this.oritation = oritation;
}
public BounceRecyclerView(Context context) {
this(context, null);
}
public BounceRecyclerView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public BounceRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
paddingTop = getPaddingTop();
paddingBottom = getPaddingBottom();
paddingLeft = getPaddingLeft();
paddingRight = getPaddingRight();
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BounceRecyclerView, defStyle,