Android XML中多个RecyclerViews的滚动问题
在xml中使用多个RecyclerView,前两个RecyclerView(水平)和第三个RecyclerView(垂直) 正如您在下面的屏幕截图中所看到的,无论何时,我滚动它都只滚动第三个RecyclerView,而不是我正在使用的两个RecyclerView 然而,如果我滚动(向上滚动或向下滚动),我想滚动所有这些RecyclerViewAndroid XML中多个RecyclerViews的滚动问题,android,xml,android-recyclerview,scrollview,Android,Xml,Android Recyclerview,Scrollview,在xml中使用多个RecyclerView,前两个RecyclerView(水平)和第三个RecyclerView(垂直) 正如您在下面的屏幕截图中所看到的,无论何时,我滚动它都只滚动第三个RecyclerView,而不是我正在使用的两个RecyclerView 然而,如果我滚动(向上滚动或向下滚动),我想滚动所有这些RecyclerView 尝试通过以下方式扩展listview以支持自定义滚动: import android.content.Context; import android.su
尝试通过以下方式扩展listview以支持自定义滚动:
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import java.lang.reflect.Field;
public class ParallaxRecyclerView extends RecyclerView {
private State state;
private Recycler recycler;
public ParallaxRecyclerView(Context context) {
this(context,null);
}
public ParallaxRecyclerView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public ParallaxRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Field fieldState = null;
Field fieldRecycler = null;
try {
fieldState = this.getClass().getSuperclass().getDeclaredField("mState");
fieldState.setAccessible(true);
state = (State) fieldState.get(this);
fieldRecycler = this.getClass().getSuperclass().getDeclaredField("mRecycler");
fieldRecycler.setAccessible(true);
recycler = (Recycler)fieldRecycler.get(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
public void scrollHorizontallyBy(int dx){
getLayoutManager().scrollHorizontallyBy(dx,recycler,state);
}
public void scrollVerticallyBy(int dy){
getLayoutManager().scrollVerticallyBy(dy,recycler,state);
}
}
然后将滚动列表添加到顶部回收视图中,并将滚动增量值传递给
scrollHorizontallyBy
例如:
topRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
...
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
parallaxRecyclerView.scrollHorizontallyBy(dx);
parallaxRecyclerView.scrollVerticallyBy(dy);
}
...
})
我已经找到了最好、最简单的解决方案,我只是复制了ScrollView中的所有内容,并将
高度
用作第三个和垂直回收视图的包装内容
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
......
</ScrollView>
您是否为recyclerview应用了
setNestedScrollingEnabled(false)
?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
......
</ScrollView>
compile 'com.android.support:recyclerview-v7:23.2.1'