2017-11-20 3 views
-1

arbeitete ich versuchen RecyclerView in SwipeRefreshLayout aber SwipeRefreshLayout nichtRecyclerView in SwipeRefreshLayout nicht

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

    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/swiperefresh" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

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

</android.support.constraint.ConstraintLayout> 

Was ich ändern müssen?

+0

Können Sie ausführlich bitte teilen, was Problem konfrontiert ist? –

+0

Welche Details kann es geben. Ich ziehe den Top-Down-Bildschirm und die Lade-Animation erscheint nicht. Nichts passiert. Vorher war eine einfache Liste von allem – ip696

+0

natürlich gearbeitet. auch wenn es nicht eine Animation sollte auf jeden Fall erscheinen – ip696

Antwort

-1

auf diese Weise versuchen activity_my.xml

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

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

und die Aktivitätsklasse geht so MainActivity

public class MyActivity extends Activity { 

    private RecyclerView recyclerView; 
    private SwipeRefreshLayout refreshLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_my); 
     refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); 
     refreshLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); 
     refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
      @Override 
      public void onRefresh() { 

      } 
     }); 

     recyclerView = (RecyclerView) findViewById(R.id.recycler_view); 
     final LinearLayoutManager layoutParams = new LinearLayoutManager(this); 
     recyclerView.setLayoutManager(layoutParams); 
     SomeAdapter adapter = new SomeAdapter(this); 
     recyclerView.setAdapter(adapter); 
     recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { 
      @Override 
      public void onScrollStateChanged(int newState) { 
      } 

      @Override 
      public void onScrolled(int dx, int dy) { 
       refreshLayout.setEnabled(layoutParams.findFirstCompletelyVisibleItemPosition() == 0); 
      } 
     }); 
    } 
} 

https://gist.github.com/VladSumtsov/ad4e13511a9b73ff3b13

+0

sieht wie Krücke aus. und setOnScrollListener ist veraltet – ip696

+0

hast du es sogar versucht? –

Verwandte Themen