我无法禁用滚动RecyclerView.我试着打电话rv.setEnabled(false)但我仍然可以滚动.
如何禁用滚动?
我按照本教程实现了滚动时隐藏工具栏和FAB的行为:https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling (第3部分)/
我已经粘贴了下面的行为示例.
现在,而不是仅包含textView的选项卡中的recyclerview中的那些单独项目,我已对其进行编码,以便它们保持图片(ImageView)并在其下方显示项目列表的回收者视图.
因此,有一个外部回收者视图,其中包含内部回收者视图列表.
内部的recyclerview不会滚动 - 我通过覆盖方法canScrollVertically()跟踪此线程中的答案来禁用它:禁用在子级Recyclerview android中的滚动.我也尝试启用滚动内部回收视图,但我遇到了同样的问题.
外部的recyclerview会滚动并具有显示/隐藏工具栏和FAB的行为.
当我通过按住图片(ImageView)滚动时,应用程序行为完全正常,显示并隐藏工具栏和FAB.但是,当我将手指放在内部回收站视图上进行滚动时,外部回收站视图会滚动并且列表会上下移动,但是显示/隐藏工具栏和FAB的行为永远不会被激活.
我有一种感觉,这是因为内部的recyclerview拦截了滚动而外部的recyclerview没有得到滚动事件来激活行为.
有谁知道如何确保外部的recyclerview也获得滚动事件,以便行为有效?
android floating-action-button android-toolbar android-recyclerview
我有一个在CoordinatorLayout中托管的垂直RecyclerView,具有折叠工具栏布局.此RecyclerView的ViewHolder包含另一个带有GridLayoutManager的RecyclerView.
这种嵌套的原因是内部RecyclerView显示的图片集合可以包含1-20张图片.我不知道会有多少张图片,但Grid的跨度必须始终为3.每次绑定ViewHolder时,我都会调整RecyclerView的布局参数以容纳内容.
如果没有CollapsingToolBarLayout,这很有效.但是,如果有一个折叠的工具栏,用我的手指在内部RecyclerView上滚动不会滚动折叠工具栏,但滚动另一个项目却会.
要重新强调,在绑定的ViewHolder中,如果我开始滚动除嵌套的RecyclerView之外的任何其他项目,滚动工作正常.但是,如果我在嵌套的RecyclerView上开始滚动,那么它会中断.
是否可以阻止内部RecyclerView上的滚动拦截,只允许父滚动?我希望内部的RecyclerView仍能处理点击.
以下是该现象的YouTube链接:https://youtu.be/fzj7HmqskzU
以下是父RecyclerView的XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivityFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
app:contentScrim="?attr/colorPrimary"
app:layout_collapseParallaxMultiplier="0.7"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<View
android:id="@+id/header_view"
android:layout_width="match_parent"
android:layout_height="192dp"
android:animateLayoutChanges="true"
android:background="@color/primary" />
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:elevation="4dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/Theme.AppCompat.NoActionBar"
app:theme="@style/Theme.AppCompat.NoActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
这是托管嵌套RecyclerView的主要ViewHolder:
public class SimpleAdapter extends RecyclerView.Adapter<SimpleAdapter.ViewHolder> {
private static final int MODEL_OBJECT = 1;
private List<ModelObject> modelObjects;
private Context context;
private int imageSize;
public SimpleAdapter(List<ModelObject> modelObjects) …Run Code Online (Sandbox Code Playgroud) android-recyclerview androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout
我有一个充满卡片的父回收视图,每张卡片内部都有一个内部回收视图。
卡片内内部 recyclerview 的滚动已被禁用,但这也影响了内部 recyclerview 接收点击事件的能力。
为了禁用滚动,我遵循了与 Lucas Crawford 的回答非常相似的方法here,它建议您创建一个自定义的 recyclerview 类并覆盖 dispatchTouchEvent: Disable Scrolling in child Recyclerview android
我的课是这样的:
public class ScrollThroughRecyclerView extends RecyclerView {
private boolean isOnClick;
public ScrollThroughRecyclerView(Context context) {
super(context);
}
public ScrollThroughRecyclerView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollThroughRecyclerView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final int actionMasked = action & MotionEvent.ACTION_MASK;
Log.e("actionmasked", "" + actionMasked);
switch (actionMasked) …Run Code Online (Sandbox Code Playgroud) 我想把一个RecyclerView放在里面ScrollView.但是ScrollView不滚动而且RecyclerView确实如此但我不希望它...我该怎么办?
我试过这个类/sf/answers/2115590501/,实际上RecyclerView不再滚动,但也没有ScrollView.
有没有帮助,ScrollView即使与残疾人一起工作RecyclerView?提前致谢.
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="jahirfiquitiva.projects.activities.DeveloperActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<ScrollView
android:id="@+id/osv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:fillViewport="true"
android:gravity="center"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<ImageView
android:id="@+id/photoJahir"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.2"
android:paddingBottom="@dimen/lists_padding"
android:paddingTop="@dimen/lists_padding"
android:text="@string/developer_bio"
android:textSize="@dimen/abc_text_size_subtitle_material_toolbar" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dividers_about_section"
android:alpha="0.3"
android:background="@color/primary" />
<RecyclerView
android:id="@+id/buttonsGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/lists_padding"
android:paddingTop="@dimen/lists_padding" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dividers_about_section"
android:alpha="0.3"
android:background="@color/primary" …Run Code Online (Sandbox Code Playgroud)