0

У меня есть макет ниже.RecyclerView не может прокручиваться, когда вставляются в RelativeView и SwipeToRefresh

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

Это в основном имеющие recyclerView внедренный в SwipeToRefresh. Это хорошо работает, когда я могу прокручивать свой recyclerView вверх и вниз. Когда вы достигаете вершины, и я спускаюсь, появляется Refresh.

Учитывая, что мне нужно добавить пустой вид Динамически, я обернул пустой вид и 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> 

Добавив этот RelativeLayout между RecyclerView и SwipeToRefreshLayout, то 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

Смежные вопросы