用个RelativeLayout套住 设置 android:nestedScrollingEnabled=“false”
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recommend_recyclerView"
android:layout_width="match_parent"
android:orientation="vertical"
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
重写
public class NoScrollRecycleView extends RecyclerView {
public NoScrollRecycleView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NoScrollRecycleView(Context context) {
super(context);
}
public NoScrollRecycleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
RecyclerView Listview都一样