0

我有以下布局。在RelativeView和SwipeToRefresh下嵌入时,RecyclerView无法向上滚动

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/my_swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

</android.support.v4.widget.SwipeRefreshLayout> 

它基本上具有嵌入在SwipeToRefresh一个recyclerView。这适用于我可以上下滚动我的recyclerView的地方。当到达顶端,我拉下来,刷新发生。

鉴于我需要动态地添加一个空视图,我已将空视图和RecyclerView包装在RelativeLayout下。这如下。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/my_swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

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

     <include 
      android:id="@+id/my_empty_view" 
      layout="@layout/fragment_empty_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:visibility="gone" /> 
    </RelativeLayout> 

</android.support.v4.widget.SwipeRefreshLayout> 

通过添加该RelativeLayoutRecyclerViewSwipeToRefreshLayout之间的RecyclerView只能向下滚动。它不能向上滚动,因为每当我尝试向上滚动时,都会发生SwipeToRefresh

为什么这是一个问题?有没有办法在保留我的布局的情况下解决问题?

谢谢!

+0

显然,问题在https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type报道%20Status%20Owner%20Summary%20Stars&GROUPBY =&排序=&ID = 78191。 – Elye

回答

0

可滚动视图必须立即嵌入到SwipeRefreshLayout中。因此,您可以让RelativeLayout嵌入到ScrollView中,并将ScrollView嵌入到SwipeRefreshLayout中。

像这样:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/my_swipe_container" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
> 
    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

    <include 
     android:id="@+id/my_empty_view" 
     layout="@layout/fragment_empty_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:visibility="gone" /> 
    </RelativeLayout> 
</ScrollView> 
</android.support.v4.widget.SwipeRefreshLayout> 
+0

为了帮助您更好地回答问题,请确保除文本解决方案外还包含一些代码。 – buczek

相关问题