3

我有一个xml布局,有以下意见Scrollview-> RelativeLayout->一些视图+ Tablayout + ViewPager-> Recylerview(在ViewPager的片段)。 ViewPager有一些固定的高度(保持它“Wrap_Content”根本不显示它)。现在问题是Recylerview从不滚动。我已经尝试了几种解决方案,如“嵌套滚动视图”或甚至让子LinearLayout已经发布像Wraping viewpager。但没有工作。Recyclerview里面的ViewPager滚动视图不工作

下面是我的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> 

而且片段Viewpager是显示具有以下布局的xml:

<?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> 

我一直在使用nestedScrollingEnabled尝试和Recyclerview也setFixedHeight性能。但是没有任何工作。

+1

我想你应该从相对布局回收视图本身有自己的滚动删除滚动视图。 –

+0

@RounakLahoti我的布局有很多需要滚动的视图。我没有为该RecyclerView使用srollview。 Recylerview也是布局中的一个子元素,它在其他视图旁边显示另一个数据列表(TextView,ImageView,EditView的组合)。 –

回答

0

添加NestedScrollView也然后设置recyclerView.setNestedScrollingEnabled(false);

检查您是否已经有这个android.support.v7.widget.RecyclerView

记住RecyclerView元素有自己的滚动

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

android.support.v4.widget.NestedScrollView适用于所有版本的更换滚动型。

<?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> 

我希望它的作品! :)如果它不工作,让我知道!我会试图找出它为什么不工作:)祝你有美好的一天!

+1

我已经使用了你所说的相同方法。但它根本不起作用。 –

+0

我看到你的帖子在它下面!我做了这样的事情,但我自定义了ImageView!所以!你找到答案了吗? @SairaNawaz – Cristofer

1

我想通了,问题是不与RecyclerViewViewPager滚动型,但ViewPager问题是与滚动型。当我把ViewPager里面ScrollView它的Wrap_Content属性不工作所以一个固定的高度限制RecyclerView内容完全显示。所以我解决了这个问题定制ViewPager的onMeasure方法,它工作顺利。无需在NestedScroll视图或其他给定解决方案中进行换行。

下面是代码为我的CustomView寻呼机时为孩子添加到滚动型,它包装内容:

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; 
    } 
} 
相关问题