2017-07-24 45 views
0

我有此佈局>RecyclerView一個滾動視圖內

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:id="header_content" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      > 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/moods_recyclerview" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" 
       android:scrollbars="none" /> 

      <android.support.v4.view.ViewPager 
       android:id="@+id/mainwindow_view_pager" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" /> 
     </LinearLayout> 

    </ScrollView> 


    <android.support.design.widget.TabLayout 
     android:id="@+id/mainwindow_tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:background="@drawable/view_border_top" /> 
</LinearLayout> 

的d ViewPager片段有此代碼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/net_rclerview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="none" 
     android:layout_weight="0" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp"/> 
</LinearLayout> 

我想要的

header_content佈局

當視圖-尋呼機片段

內的

net_rclerview被滾動到滾動出來。 問題是recyclerview正在滾動,但上面的內容沒有滾動出來的視圖,,這是可能實現的,如果有任何其他選項我可以做?而不是

+0

make RecyclerView.setNestedScrollingEnabled(false);你的回收站 –

+0

@NileshRathod沒有不工作:( –

+0

你找到了這個問題的解決方案? –

回答

1

使用NestedScrollViewScrollView

<android.support.v4.widget.NestedScrollView 
      android:id="@+id/nestedScrollingView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fillViewport="true" 
      android:fitsSystemWindows="true" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

RecyclerView.setNestedScrollingEnabled(false);recyclerview

+0

它不工作的人 –

+0

我忘了提及所有這些代碼是在一個主viewpager裏面:MainWindow> Viewpager> ScrollView {Content And View pager} - > RecylereView –

0

我只是碰到類似的問題,很多衝浪的我想通了,問題是不是以後就與RecyclerView但與ViewPage r。 將ViewPager的WrapContent屬性放入ScrollView時不起作用。因此,固定的高度限制RecyclerView以showUp全部內容。只是更新ViewPager的在線測量方法如下:

public class CustomViewPager extends ViewPager { 

    boolean canSwipe = true; 

    public CustomViewPager(Context context) { 
     super(context); 
    } 

    public CustomViewPager(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     View child = getChildAt(getCurrentItem()); 
     if (child != null) { 
      child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
      int h = child.getMeasuredHeight(); 
      heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY); 
     } 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    } 

    public void canSwipe(boolean canSwipe) { 
     this.canSwipe = canSwipe; 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if (this.canSwipe) { 
      return super.onTouchEvent(event); 
     } 

     return false; 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent event) { 
     if (this.canSwipe) { 
      return super.onInterceptTouchEvent(event); 
     } 

     return false; 
    } 
} 

它爲我工作。希望它也適用於你。

相關問題