RecyclerView ,ListView 只显示一行元素

用个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都一样


版权声明:本文为weixin_45579870原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。