草庐IT

android - 当我将水平 recyclerview 滚动到垂直 recyclerview 时,Nestedscrollview 跳起来

coder 2023-12-28 原文

我有这样的布局结构

首页 Activity :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.minvideo.android.activities.HomeActivity"
    android:background="@color/colorWhite"
    >

   <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
   </FrameLayout>

    <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

底部菜单 fragment :

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/colorWhite"
>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:visibility="visible"
        android:contentInsetLeft="0dp"
        android:contentInsetStart="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        android:contentInsetRight="0dp"
        android:contentInsetEnd="0dp"
        app:contentInsetRight="0dp"
        app:contentInsetEnd="0dp"
        >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            >
            <com.minvideo.android.views.RippleView
                android:id="@+id/toolbar_left_control_ripple"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:rv_rippleDuration="200"
                app:rv_color="@color/colorGray"
                app:rv_centered="true"
                app:rv_type="simpleRipple"
                >
                <RelativeLayout
                    android:id="@+id/toolbar_left_control_wrap"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:paddingRight="20dp"
                    android:paddingEnd="20dp"
                    android:paddingLeft="20dp"
                    android:paddingStart="20dp"
                    >

                    <ImageView
                        android:id="@+id/toolbar_left_control"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_centerVertical="true"
                        android:contentDescription="@string/left_control"
                        android:scaleType="fitXY"
                        android:visibility="visible"
                        app:srcCompat="@drawable/ic_search" />

                </RelativeLayout>
            </com.minvideo.android.views.RippleView>
            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:text="test"
                android:textColor="#ffffff"
                android:gravity="center"
                android:layout_marginLeft="44dp"
                android:layout_marginStart="44dp"
                android:layout_marginRight="44dp"
                android:layout_marginEnd="44dp"
                />
            <com.minvideo.android.views.RippleView
                android:id="@+id/toolbar_right_control_ripple"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:rv_rippleDuration="200"
                app:rv_color="@color/colorGray"
                app:rv_centered="true"
                app:rv_type="simpleRipple"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                >
                <RelativeLayout
                    android:id="@+id/toolbar_right_control_wrap"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:paddingRight="20dp"
                    android:paddingEnd="20dp"
                    android:paddingLeft="20dp"
                    android:paddingStart="20dp"
                    >

                    <ImageView
                        android:id="@+id/toolbar_right_control"
                        android:layout_width="24dp"
                        android:layout_height="20dp"
                        android:layout_centerVertical="true"


                 android:contentDescription="@string/right_control"
                            android:scaleType="fitXY"
                            android:visibility="visible"
                            app:srcCompat="@drawable/ic_likesettings" />
                    </RelativeLayout>
                </com.minvideo.android.views.RippleView>
            </RelativeLayout>
        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="fill"
            android:paddingLeft="20dp"
            android:paddingStart="20dp"
            android:paddingRight="20dp"
            android:paddingEnd="20dp"
            android:clipToPadding="false"
            />

    </android.support.design.widget.AppBarLayout>

    <com.minvideo.android.views.CustomViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"          
        />

</android.support.design.widget.CoordinatorLayout>

TabFragment(tablayout 中每个标签的 fragment ):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    android:paddingTop="10dp">


    <com.minvideo.android.views.TabObservableScrollViewWithPaging
        android:id="@+id/rv_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:fillViewport="true"
        android:layout_gravity="fill_vertical"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                />

        </LinearLayout>

    </com.minvideo.android.views.TabObservableScrollViewWithPaging>

    <ProgressBar
        android:id="@+id/progress_bar"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:visibility="gone"
        />

    <TextView
        android:id="@+id/tab_empty_list_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:text="@string/clips_empty_list_text"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:gravity="center"
        />

    <RelativeLayout
        android:id="@+id/tab_timeout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="16dp"
        android:visibility="gone"
        tools:visibility="visible"
       >

    <TextView
        android:id="@+id/tab_timeout_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:text="@string/check_your_connection"
        android:gravity="center"
        />

    <com.minvideo.android.views.RippleView
        android:id="@+id/retry_ripple"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tab_timeout_text"
        android:layout_centerHorizontal="true"
        app:rv_rippleDuration="200"
        app:rv_color="@color/colorGray"
        app:rv_centered="true"
        app:rv_type="simpleRipple"
        >

        <ImageView
            android:id="@+id/retry"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:tint="@color/colorAccent"
            app:srcCompat="@drawable/ic_refresh_black_24dp"
            android:layout_margin="5dp"
            />

    </com.minvideo.android.views.RippleView>


</RelativeLayout>


<TextView
    android:id="@+id/tab_server_error_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    android:text="@string/internal_server_error"
    android:layout_centerInParent="true"
    android:visibility="gone"
    android:gravity="center"
    />

<TextView
    android:id="@+id/tab_no_internet_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    android:text="@string/no_internet_title"
    android:layout_centerInParent="true"
    android:visibility="gone"
    android:gravity="center"
    />

<RelativeLayout
    android:id="@+id/save_wrap"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center"
    android:background="@color/colorWhite"
    android:visibility="gone"
    >
    <ProgressBar
        android:id="@+id/progress_bar_save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:layout_margin="10dp"
        />
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorGray"
        />
    <RelativeLayout
        android:id="@+id/save_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:padding="10dp"

      android:background="@drawable/detail_user_button_follow_23_blue"
        android:layout_centerInParent="true"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Save changes"
            android:textColor="@color/colorWhite"
            />
    </RelativeLayout>
</RelativeLayout>


</RelativeLayout>

项目布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:id="@+id/root"
 android:layout_marginBottom="25dp"
 >

<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="20dp"
    android:layout_marginStart="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginEnd="20dp"
    android:maxLines="2"
    android:ellipsize="end"
    style="@style/header"
    />

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:paddingStart="20dp"
    android:paddingRight="20dp"
    android:paddingEnd="20dp"
    android:clipToPadding="false"
    android:layout_below="@+id/title"
    />

</RelativeLayout>

当我第一次打开 Activity 时一切正常,但是当我从其他 Activity 返回到 Home Activity 时,当我滚动内部水平 RecyclerView 时,RecyclerView 会跳起来。外部垂直回收 View 和内部水平回收 View :

rv.setNestedScrollingEnabled(false);

如果我打电话

universalAdapter.notifyDataSetChanged();

一切正常,但在所有水平回收站 View 上更改滚动位置 帮我修复这个没有 universalAdapter.notifyDataSetChanged();

的错误

最佳答案

我摆脱了这个“在水平滚动内部 recylcer View 时在外部 View 中跳转”的问题,通过引入下面一行解决。

android:descendantFocusability="blocksDescendants"

如评论中的原始发帖人所述

<LinearLayout 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="
   android:descendantFocusability="blocksDescendants" >  
   
   <android.support.v7.widget.RecyclerView 
      android:id="@+id/rv" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"  
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:focusableInTouchMode="true" /> 
</LinearLayout>

关于android - 当我将水平 recyclerview 滚动到垂直 recyclerview 时,Nestedscrollview 跳起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45957476/

有关android - 当我将水平 recyclerview 滚动到垂直 recyclerview 时,Nestedscrollview 跳起来的更多相关文章

  1. ruby-on-rails - 如果我将 ruby​​ 版本 2.5.1 与 rails 版本 2.3.18 一起使用会怎样? - 2

    如果我使用ruby​​版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby​​1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更

  2. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  3. ruby - 在 Ruby 中,垂直线是什么? - 2

    1.upto(9){|x|printx}为什么这行不通?{printx|x}}y呢? 最佳答案 它用于传递给您的block的参数。即在您的示例中,upto将使用1到9中的每个数字调用您的block,当前值可作为x获得。block参数可以有任何名称,就像方法参数一样。例如1.upto(9){|num|putsnum是有效的。就像一个方法的参数一样,一个block也可以有多个参数。例如hash.each_pair{|key,value|puts"#{key}is#{value}"} 关于ru

  4. ruby-on-rails - ruby:将数组的每个元素用附加引号引起来 - 2

    我有以下字符串:a="001;Barbara;122"我拆分成字符串数组:names=a.split(";")names=["001","Barbara","122"]我应该怎么做才能将每​​个元素另外用''引号括起来?结果应该是names=["'001'","'Barbara'","'122'"]我知道这听起来很奇怪,但我需要它在ruby​​onrails中进行数据库查询。出于某种原因,如果我的名字在“”引号中,我将无法访问数据库记录。我在数据库中确实有mk1==0006但rails不想以某种方式访问​​它。但是,它确实访问1222。sql="SELECTmk1,mk2,pk1,pk

  5. ruby-on-rails - 我将 Rails3 与 tinymce 一起使用。如何呈现用户关闭浏览器javascript然后输入xss? - 2

    我有一个用Rails3编写的站点。我的帖子模型有一个名为“内容”的文本列。在帖子面板中,html表单使用tinymce将“content”列设置为textarea字段。在首页,因为使用了tinymce,post.html.erb的代码需要用这样的原始方法来实现。.好的,现在如果我关闭浏览器javascript,这个文本区域可以在没有tinymce的情况下输入,也许用户会输入任何xss,比如alert('xss');.我的前台会显示那个警告框。我尝试sanitize(@post.content)在posts_controller中,但sanitize方法将相互过滤tinymce样式。例如

  6. ruby-on-rails - Ruby on Rails 中的水平数据库扩展 - 2

    我有一个RubyonRails应用程序和一个具有以下结构的PostgreSQL数据库:classA只有几个A,而且增长缓慢(比如一个月5个)。每个A有数千个B,每个B有数万个C(因此每个A有数百万个C)。A是独立的,并且永远不会同时需要来自不同A的B和C(即在同一查询中)。我的问题是现在我只有几个A,ActiveRecord查询需要很长时间。当C的表有数千万行时,查询将永远无法进行。我正在考虑水平扩展数据库(即A的一张表,B的一张表和每个A的一张C的表)。但我不知道该怎么做。我猜这是一种分片,但我无法弄清楚如何动态创建数据库表并使用ActiveRecord访问数据(如果该表取决于我正在

  7. ruby-on-rails - 为什么我的 Rails 服务器渲染时间不加起来? - 2

    我的Rails应用程序在暂存服务器上运行速度非常慢,这让我遇到了一些麻烦。最令人困惑的是每个请求的日志输出的最后一行。看起来View和数据库时间甚至不接近整个渲染时间。在一页上,完成时间大约1000毫秒,View大约450毫秒,数据库大约20毫秒。渲染页面所需的其余时间从何而来? 最佳答案 当事情变得神秘时......分析器是你的friend!分析器将统计哪些方法被调用最多以及每个方法调用花费多长时间。ruby-prof当我在RubyLand时,它会帮我解决这个问题,它会生成一个漂亮的调用图(如果需要,可以是html格式),这使得查

  8. ruby-on-rails - Ruby on Rails 平均水平? - 2

    有没有一种简单的方法可以获取集合中某个属性的平均值?例如,每个用户都有一个分数。给定一组用户(@users),您如何获得该组的平均分?有没有类似@users.average(:score)的东西?我想我在数据库字段中遇到过类似的东西,但我需要它来处理集合...... 最佳答案 对于你的问题,实际上可以这样做:@users.collect(&:score).sum.to_f/@users.lengthif@users.length>0早些时候我认为,@users.collect(&:score).average会起作用。对于数据库字段

  9. ruby - 什么是最像 Ruby 的生成 3 个正整数加起来等于 100 的唯一组合的方法 - 2

    条件:a+b+c=100a,b,cpositiveintegersor0期望的输出:[[0,0,100],[0,1,99],...#allotherpermutations[99,1,0],[100,0,0]] 最佳答案 我会写:(0..100).flat_map{|x|(0..100-x).map{|y|[x,y,100-x-y]}}#=>[[0,0,100],[0,1,99]],...,[99,1,0],[100,0,0]]站点注释1:这是一个经典示例,其中列表推导式大放异彩(如果某处有条件则更是如此)。由于Ruby没有LC,我

  10. ruby floats 根据顺序加起来不同的值 - 2

    所以这很奇怪。我在Ruby1.9.3中,float加法没有像我预期的那样工作。0.3+0.6+0.1=0.99999999999999990.6+0.1+0.3=1我在另一台机器上试过了,得到了同样的结果。知道为什么会发生这种情况吗? 最佳答案 浮点运算是不精确的:它们将结果四舍五入到最接近的可表示浮点值。这意味着每个float操作是:float(aopb)=mathematical(aopb)+rounding-error(aopb)如上式所示,舍入误差取决于操作数a和b。因此,如果您以不同的顺序执行操作,float(float(

随机推荐