显示片段时停止滚动CollapsingToolbarLayout

时间:2015-07-08 19:51:08

标签: android android-fragments android-viewpager android-collapsingtoolbarlayout

我在ViewPager内有一个Activity,显示两个Fragments

活动有TabLayoutCollapsingToolbarLayoutCollapsingToolbarLayout嵌套在AppBarLayoutImageView以产生视差效果。 TabLayout位于AppBarLayoutLinearLayout以外的ViewPager。当用户点击按钮以显示FrameLayout时,还有一个FragmentViewPager上显示另一个Fragment

问题在于,当RecyclerView内的Fragment覆盖在ViewPager顶部的Activity时,RecyclerView也会滚动并进行视差效果。从本质上讲,它同时滚动Fragment内的ViewPagerCollapsingToolbarLayout内的内容。

当用户看到Fragment时,有没有办法停止Fragment的滚动,只覆盖重叠<android.support.design.widget.CoordinatorLayout> <android.support.design.widget.AppBarLayout> <android.support.design.widget.CollapsingToolbarLayout app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView app:layout_collapseMode="parallax"/> <android.support.v7.widget.Toolbar /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <LinearLayout app:layout_behavior="@string/appbar_scrolling_view_behavior" > <android.support.design.widget.TabLayout /> <!-- Two fragments inside ViewPager each containing a RecyclerView --> <android.support.v4.view.ViewPager /> </LinearLayout> <!-- User Clicks a button and fragment is added to this framelayout --> <!-- This fragment overlays on top of the entire Activity layout --> <!-- This fragment also contains a recyclerview --> <FrameLayout/> </android.support.design.widget.CoordinatorLayout> 中的内容?

这就是我的XML Hierarchy的样子:

def parse_command(in_f, out_f, command):
    with open(in_f) as f, open(out_f,"a") as out:
        lines = f.readlines();
        file_list=[]
        for line in lines:
            if line.startswith('**') or not line.strip() :
                continue
            else:
                line = ' '.join(line.split())
                line = line.replace('= ','=')
                file_list.append(line+'\n')
#
        for i in range (len(file_list)):
            str=file_list[i]
            if (str.startswith(command)):
               out.write(str)
               for j in range (i+1,len(file_list)):
                   str=file_list[j]
                   if (str[0].isdigit() or str[0].isalpha()):
                       out.write(str)
                   if (str.startswith('*')):
                       break
    return

parse_command('in.txt','out.txt', '*ELEMENT' )

2 个答案:

答案 0 :(得分:11)

CoordinatorLayoutAppBarLayout通过来自儿童的onNestedScroll回调进行操作。如果你有一个滚动的孩子,你可以通过禁用这个回调来阻止它影响其父/:

recyclerView.setNestedScrollingEnabled(false);

答案 1 :(得分:-4)

尝试使用nestedscrollview而不是linearlayout。