2016-11-30 82 views
0

我有一个水平RecyclerViewScrollView内但没有任何适配器方法正在触发。卧式RecyclerView里面ScrollView不充气 - Android

这是我的片段与ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:background="@color/white" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <include layout="@layout/selector" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:id="@+id/selector"/> 

    ..... 
    ..... 

    </RelativeLayout> 
</ScrollView> 

这是我selector.xml布局:

<?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="100dp" 
    android:background="@color/green"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rv_kids" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" /> 

</LinearLayout> 

这里我设置适配器的RecyclerView

selectorAdapter = new selectorAdapter(activity, kids); 
rv_items.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)); 
rv_items.setAdapter(selectorAdapter); 
selectorAdapter.notifyDataSetChanged(); 

事情是,我已经设置到选择器的绿色背景显示,但没有的适配器方法被触发并且RecyclerView不会膨胀。 我能做些什么不同?

+0

使用嵌套的滚动视图 –

+0

移动setadapter – Nithinlal

+0

@Nithinlal嘿,这就是它是之前并没有工作,即使随后的setlayoutmanager线之上,所以我试过在下面移动它只是为了尝试。 – Mallika

回答

0

您应该改用嵌套滚动视图 https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html。但是,您可能需要编写自己的LayoutManager。看看这个答案SO更多细节

How to use RecyclerView inside NestedScrollView?

+0

嘿,谢谢你,让我试试看。 – Mallika

+0

谢谢,更新我,如果它的工作与否 –

+0

嘿自定义布局管理器崩溃在'查看视图= recycler.getViewForPosition(位置)',即使我正确地绑定数据与列表和适配器计数是正确的。但是,不是进一步调试,我想我会切换到使用LinearLayout并向其添加视图,并使其表现得像RecylerView。 – Mallika

相关问题