RecyclerView中的ScrollView不会滚动 [英] ScrollView inside RecyclerView won't scroll

查看:120
本文介绍了RecyclerView中的ScrollView不会滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使一个 LinearLayout (我正在向其中动态添加项目)在可滚动的 RecyclerView 中可滚动.在启动时,我最初会看到一个小的滚动条(指示它是可滚动的视图,以秒为单位逐渐消失).尝试过appCompat NestedScrollView并启用 nestedScrollingEnabled ,但没有成功.如何在 RecyclerView 内部使 LinearLayout 可滚动?

I want to make a LinearLayout (to which I'm adding items dynamically) scrollable inside a scrollable RecyclerView. On startup, I can see a little scrollbar initially (indicating it's a scrollable view, fades in seconds). Tried appCompat NestedScrollView as well as enabling nestedScrollingEnabled, with no success. How can I make the LinearLayout scrollable inside the RecyclerView?

<FrameLayout 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">
  <ScrollView
      android:layout_width="wrap_content"
      android:layout_height="300dp"
      android:fillViewport="true"
      android:nestedScrollingEnabled="true">
      <LinearLayout
          android:id="@+id/playerlist_linear"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:gravity="left|center_vertical"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="10dp"
          android:layout_marginTop="5dp"
          android:layout_marginBottom="7dp"
          android:orientation="vertical">
      </LinearLayout>
  </ScrollView>

</FrameLayout>

RecyclerView代码

RecyclerView code

<android.support.v7.widget.RecyclerView
    android:id="@+id/messagesListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_weight="1"
    android:nestedScrollingEnabled="false"/>

更新:我发现滚动确实可以工作,但是只有当我向鼠标发送垃圾邮件或真正快速滚动滚动视图时才滚动.只要按住鼠标,它就可以集中注意力并允许滚动.真的很奇怪.

UPDATE: I found out that scrolling does indeed work, but only if I spam the mouse or tap really fast inside the scrollview. It kind of gets focused and allows scrolling as long as mouse is held down. Really strange.

推荐答案

我通过在rafsanahmad007的解决方案中添加一行来解决了该问题:

I solved it by adding a line to rafsanahmad007's solution:

    ScrollView scrollView = (ScrollView)findViewById(R.id.scrollView1);
    scrollView.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                         // Disallow the touch request for parent scroll on touch of child view

                   view.getParent().requestDisallowInterceptTouchEvent(false);
                   view.onTouch(motionEvent);
                        return true;
                    }
                }); 

我不确定这是在Java上调用 View.onTouch 的方式,因为我正在使用Xamarin.Android(C#)进行开发.它应该非常相似.

I'm not sure that's how View.onTouch is called on Java, as I'm developing with Xamarin.Android (C#). It should be pretty similar.

这篇关于RecyclerView中的ScrollView不会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆