添加此滑动到边缘的渐渐隐藏效果:
属性如下:
requiresFadingEdge:
- none(边框颜色不变)
- horizontal(水平方向颜色变淡)
- vertical(垂直方向颜色变淡)
fadingEdgeLength:用来设置边框渐变的长度
示例:
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="40dp"/>
2:进阶,只要一部分
重写recycleView的类,重新设置返回值。
- getTopFadingEdgeStrength(); 重写这个方法,设置返回值是0,去掉顶部阴影;
- getBottomFadingEdgeStrength(); 重写这个方法,设置返回值是0,去底顶部阴影
- getLeftFadingEdgeStrength(); 重写这个方法,设置返回值是0,去掉左部阴影
- getRightFadingEdgeStrength(); 重写这个方法,设置返回值是0,去掉右部阴影
示例:
public class RecycleViewCustomer extends RecyclerView {
public RecycleViewCustomer(@NonNull Context context) {
super(context);
}
public RecycleViewCustomer(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public RecycleViewCustomer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
/**
* 重写这个方法,返回值是0,去掉顶部阴影
*
* @return
*/
@Override
protected float getTopFadingEdgeStrength() {
return super.getTopFadingEdgeStrength();
}
/**
* 重写这个方法,返回值是0,去底顶部阴影
*
* @return
*/
@Override
protected float getBottomFadingEdgeStrength() {
//return super.getBottomFadingEdgeStrength();
return 0;
}
/**
* 重写这个方法,返回值是0,去左顶部阴影
*
* @return
*/
@Override
protected float getLeftFadingEdgeStrength() {
return super.getLeftFadingEdgeStrength();
}
/**
* 重写这个方法,返回值是0,去底右部阴影
*
* @return
*/
@Override
protected float getRightFadingEdgeStrength() {
return super.getRightFadingEdgeStrength();
}
}