Tôi đang triển khai RecyclerView
bên trong một ScrollView
. Để chỉ có một hành vi cuộn trên toàn bộ trang, tôi triển khai phiên bản NonScrollRecyclerView
. Việc thực hiện như sau:Non Scroll RecyclerView vấn đề cuộn trong SDK Android 23
public class NonScrollRecyclerView extends RecyclerView {
public NonScrollRecyclerView(Context context) { super(context); }
public NonScrollRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
if(ev.getAction() == MotionEvent.ACTION_MOVE)
return true;
return super.dispatchTouchEvent(ev);
}
}
Khi tôi cập nhật xây dựng và mục tiêu của tôi thiết lập để SDK 23, tôi gặp khó khăn khi di chuyển các trang chứa NonScrollRecyclerView
. Vấn đề cụ thể là trang cuộn OK cho đến khi tôi đạt đến phần xem trình tái chế và khi tôi cuộn lên chế độ xem này, tôi không thể cuộn nữa, lên hoặc xuống.
tôi donot phải đối mặt với vấn đề này với SDK 22 và dưới
xml của tôi là như sau:
XML@layout/rv
chứa quan điểm tái chế
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_gray">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_gray"
android:orientation="vertical">
<include
layout="@layout/row_mall_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv_mall_header"
android:layout_marginTop="8dp"/>
<include
layout="@layout/row_mall_shops"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv_mall_shops"
android:layout_marginTop="8dp"/>
<include
layout="@layout/row_mall_coupons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv_mall_coupons"
android:layout_marginTop="8dp"/>
<include
layout="@layout/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv_mall_feeds"
android:layout_marginTop="8dp"/>
</LinearLayout>
</ScrollView>
XML - @ layout/rv
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_gray"
android:id="@+id/ll_mall_feeds">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingTop="6dp"
android:paddingBottom="6dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_feedcount"
android:textColor="@color/semi_theme_blue"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="12dp"
android:layout_centerVertical="true" />
</RelativeLayout>
<com.project.ui.NonScrollRecyclerView
android:id="@+id/nrv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/transparent"
android:listSelector="@android:color/transparent" />
</LinearLayout>
Tại sao bạn không chỉ sử dụng LinearLayout thay vì RecyclerView? Về cơ bản, bạn đang chuyển RecyclerView thành LinearLayout, nhưng với nhiều chi phí hơn. –
Đồng ý với nhận xét ở trên, chỉ cần loại bỏ recyclerView và nếu bạn xem xét điều này, bạn sẽ không hỏi về các vấn đề bố cục xml nữa http: // stackoverflow.com/questions/29956014/why-should-we-use-xml-layouts – Nanoc
bạn có thể tạo quản lý bố cục tuyến tính riêng theo yêu cầu của bạn ... kiểm tra liên kết này https://github.com/serso/android-linear- layout-manager/blob/master/lib/src/main/java/org/solovyev/android/views/llm/LinearLayoutManager.java –