3

Ich habe ein XML-Layout mit folgenden Ansichten Scrollview-> RelativeLayout-> Einige Ansichten + Tablayout + ViewPager-> Recylerview (In Fragment von ViewPager). ViewPager hat eine feste Höhe (Keeping it "Wrap_Content" zeigt es überhaupt nicht). Nun ist das Problem, dass Recylerview nie scrollt. Ich habe mehrere Lösungen bereits gepostet wie Wrapping Viewpager innerhalb "verschachtelte Scrollview" Oder sogar Kind von LinearLayout. Aber nichts hat funktioniert.Recyclerview innerhalb ViewPager innerhalb scrollview funktioniert nicht

Unten ist mein xml:

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/btn_startdraw" 
     android:fillViewport="true" 
     android:gravity="center"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:padding="@dimen/_5sdp"> 


      <TextView 
       android:id="@+id/invites_accepted" 
       style="@style/bodyStyleBlue" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/committee_slots" 
       android:text="@string/invites_accepted" /> 

       <!-- A lot of other Textfields for data display--> 

       <android.support.design.widget.TabLayout 
       android:id="@+id/tabs_pendingcommittee" 
       style="@style/TabStyle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/draw_mode_val" 
       app:tabMode="fixed"></android.support.design.widget.TabLayout>b 


      <com.apponative.committeeapp.ui.custom.CustomViewPager 
       android:id="@+id/pending_member_view" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/_250sdp" 
       android:layout_below="@+id/tabs_pendingcommittee" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     </RelativeLayout> 
    </android.support.v4.widget.NestedScrollView> 

    <!-- Some other views on bottom--> 
</RelativeLayout> 

Und Fragment dass Viewpager zeigt xml hat folgenden Aufbau:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white"> 

    <TextView 
     style="@style/bodyStyleBold1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="No People..." /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/contact_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/title" 
     android:background="@color/white"></android.support.v7.widget.RecyclerView> 
</FrameLayout> 

ich versucht habe, mit nestedScrollingEnabled und auch setFixedHeight Eigenschaften auf Recyclerview. Aber nichts hat funktioniert.

+1

Ich denke, Sie sollten scroll Ansicht von Relative Layout als Recycler Ansicht selbst hat seine eigenen scroller entfernen. –

+0

@RounakLahoti Mein Layout hat viele Ansichten, die gescrollt werden müssen. Ich verwende keine srollview für diese RecyclerView. Recylerview ist auch ein Kind im Layout, das neben anderen Ansichten eine andere Liste von Daten anzeigt (eine Kombination aus TextView, ImageView, EditView). –

Antwort

0

NestedScrollView Hinzufügen und auch dann recyclerView.setNestedScrollingEnabled(false);

Überprüfen Sie, dass Sie dies bereits android.support.v7.widget.RecyclerView

Denken Sie daran, dass das RecyclerView Element sein eigenes scroller

<android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

Ersetzen Scrollview mit android.support.v4.widget.NestedScrollView funktioniert auf allen Versionen hat .

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.NestedScrollView 
     style="@style/ScrollBarStyle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/btn_startdraw" 
     android:fillViewport="true" 
     android:gravity="center"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:padding="@dimen/_5sdp"> 


      <TextView 
       android:id="@+id/invites_accepted" 
       style="@style/bodyStyleBlue" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/committee_slots" 
       android:text="@string/invites_accepted" /> 

       <!-- A lot of other Textfields for data display--> 

       <android.support.design.widget.TabLayout 
       android:id="@+id/tabs_pendingcommittee" 
       style="@style/TabStyle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/draw_mode_val" 
       app:tabMode="fixed"></android.support.design.widget.TabLayout>b 


      <com.apponative.committeeapp.ui.custom.CustomViewPager 
       android:id="@+id/pending_member_view" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/_250sdp" 
       android:layout_below="@+id/tabs_pendingcommittee" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     </RelativeLayout> 
    </android.support.v4.widget.NestedScrollView> 

    <!-- Some other views on bottom--> 
</RelativeLayout> 

Ich hoffe, es funktioniert! :) Wenn es nicht funktioniert, lass es mich wissen! Ich werde versuchen herauszufinden, warum es nicht funktioniert :) Einen schönen Tag noch!

+1

Ich habe die gleiche Methode verwendet, wie Sie gesagt haben. Aber es funktioniert überhaupt nicht. –

+0

Ich habe deinen Beitrag darunter gesehen!Ich habe so etwas gemacht, aber ich habe das ImageView angepasst! Damit! Hast du die Antwort gefunden? @SairaNawaz – Cristofer

1

Ich fand heraus, dass nur Problem innerhalb ViewPager oder Scroll, aber Problem war mit ViewPager innen Scroll nicht mit RecyclerView war. Wenn ich setzen ViewPager innerhalb ScrollView seine Wrap_Content Eigenschaft funktionierte nicht so Eine feste Höhe beschränken RecyclerView Inhalte vollständig angezeigt werden. Also habe ich dieses Problem gelöst durch Anpassung ViewPager OnMeasure Methode und es funktioniert reibungslos. Sie müssen nicht in die NestedScroll-Ansicht oder andere gegebene Lösungen einbinden.

Im Folgenden finden Sie Code für meinen Custom Pager, den Inhalt hüllt, wenn es als Kind zu Scrollview hinzugefügt:

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; 
    } 
} 
Verwandte Themen