2015-08-12 3 views
7

Ich benutze Collapsing ToolBar Layout mit NestedScrollView und Viewpager in verschachtelten Scrollview.Collapsing ToolBar Layout mit Viewpager in NestedScrollView

Ich habe 3 Registerkarten und 3 Fragmente für diese Registerkarten. Diese Fragmente verwenden RecyclerView, um Daten festzulegen.

Jetzt mit den NestedScrollView und Viewpager, wenn ich den RecyclerView Inhalt scrollen, funktioniert der Zusammenbruch Effekt nicht mit diesem.

Ich muss auch NestedScrollView setzen, da ich einige Informationen habe, die ich oben Tabs zeigen muss.

Hier ist mein Code:

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

    <android.support.design.widget.CollapsingToolbarLayout 
    android:id="@+id/collapsing_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_scrollFlags="scroll|exitUntilCollapsed" 
    android:fitsSystemWindows="true" 
    app:contentScrim="?attr/colorPrimary" 
    app:expandedTitleMarginEnd="64dp" 
    app:expandedTitleMarginStart="48dp" 
    app:expandedTitleTextAppearance="@style/TransparentText"> 

    <FrameLayout 
     android:id="@+id/carouselLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     android:fitsSystemWindows="true" 
     app:layout_collapseMode="parallax"> 

     <ImageView 
      android:id="@+id/coverImage" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:src="@drawable/example" 
      android:scaleType="centerCrop"/> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:gravity="bottom" 
      android:orientation="vertical" 
      android:layout_gravity="bottom" 
      android:padding="@dimen/profile_image_margin" 
      android:background="@drawable/gradient_bg" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:layout_height="wrap_content"> 

      <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/profile_image_margin" 
      android:textSize="@dimen/text_size_xlarge" 
      android:textStyle="bold" 
      android:textColor="@color/white" 
      android:text="Title" 
      android:id="@+id/content_title"/> 

     </LinearLayout> 

    </FrameLayout> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:theme="@style/ActionBarThemeOverlay" 
      app:popupTheme="@style/ActionBarPopupThemeOverlay" 
      app:layout_scrollFlags="scroll|enterAlways" 
      android:background="@drawable/gradient_bg" /> 

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

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="fill" 
    android:isScrollContainer="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="sdjsfksdfsd" 
      android:textColor="@color/red"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="csdffsfsdfsdfsdf" 
      android:textColor="@color/red"/> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/slidingTabs" 
      android:layout_width="match_parent" 
      app:tabMode="scrollable" 
      app:tabGravity="fill" 
      android:layout_height="wrap_content"/> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:layout_height="300dp"> 

     </android.support.v4.view.ViewPager> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 

Bitte helfen Sie mir, wenn Sie eine Idee, wie Recyclerview innerhalb NestedScrollview in Android zu implementieren, so dass ich diese Arbeit bekommen kann .

+0

einen Blick auf diese http://stackoverflow.com/questions/30580954/viewpager-in -a-nestedcrollview? rq = 1 – CaptRisky

+0

können Sie bitte einen Snapshot ausarbeiten oder hochladen. Wir helfen Ihnen mit Alternativen oder der richtigen Lösung. –

+0

bitte [this] (http://inthecheesefactory.com/blog/android-design-support-library-codelab/de) –

Antwort

3

Es scheint, war dies bereits hier beantwortet: https://stackoverflow.com/a/31561790/4931825

Sie dieses Beispiel auch Besuche in der oben erwähnten Antwort bereitgestellt wird, kann https://github.com/TheLittleNaruto/SupportDesignExample/

Der Autor eine benutzerdefinierte NestedScrollView Klasse erstellt NestedScrollView erstreckt, die die onInterceptTouchEvent Methode overrode so wie:

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    final float x = ev.getX(); 
    final float y = ev.getY(); 
    switch (ev.getAction()) { 
     case MotionEvent.ACTION_DOWN: 
      xDistance = yDistance = 0f; 
      lastX = ev.getX(); 
      lastY = ev.getY(); 
      break; 
     case MotionEvent.ACTION_MOVE: 
      final float curX = ev.getX(); 
      final float curY = ev.getY(); 
      xDistance += Math.abs(curX - lastX); 
      yDistance += Math.abs(curY - lastY); 
      lastX = curX; 
      lastY = curY; 
      if (xDistance > yDistance) 
       return false; 
    } 

    return super.onInterceptTouchEvent(ev) || ev.getPointerCount() == 2; 
} 

und eine benutzerdefinierte Klasse ViewPager erstreckt ViewPager dass seine onMeasure Verfahren wie so overrode:

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)  { 
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 

    int height = 0; 
    for (int i = 0; i < getChildCount(); i++) { 
     View child = getChildAt(i); 
     child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
     int h = child.getMeasuredHeight(); 
     if (h > height) height = h; 
    } 
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); 
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
} 

Schließlich verwendete er sowohl in der CoordinatorLayout:

<com.thelittlenaruto.supportdesignexample.customview.MyNestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:id="@+id/lin" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:visibility="visible"> 

     <com.thelittlenaruto.supportdesignexample.customview.WrapContentHeightViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

</com.thelittlenaruto.supportdesignexample.customview.MyNestedScrollView> 
+0

Dies liefert keine Antwort auf die Frage. Sobald Sie genügend [Reputation] (http://stackoverflow.com/help/whats-reputation) haben, können Sie [jeden Beitrag kommentieren] (http://stackoverflow.com/help/privileges/comment); stattdessen [geben Sie Antworten, die keine Klärung durch den Fragesteller erfordern] (http://meta.stackexchange.com/questions/214173/why-doe-i-need-50-reputation-to-comment-what-can- i-do-stattdessen). - [Aus Bewertung] (/ review/low-quality-posts/14760873) – GilZ

+0

Während dieser Link die Frage beantworten kann, ist es besser, die wesentlichen Teile der Antwort hier aufzunehmen und den Link als Referenz zur Verfügung zu stellen. Nur-Link-Antworten können ungültig werden, wenn sich die verknüpfte Seite ändert. - [Aus Bewertung] (/ review/low-quality-posts/14760873) –

+0

@FelixSFD, hoffe die Bearbeitung genügt –