2

プッシュツーリフレッシュ機能を使用してリストを作成しようとしていますが、RecyclerViewをSwipeRefreshLayout内に置くとオーバースキャン効果が有効になります。リストの一番下にさえ。何が起こるかは、ユーザがリストが終了したというビジュアルキューを持っていないことです。 recyclerviewがトップの位置に達したときにリフレッシュを有効にすることができSwipeRefreshLayout内でRecyclerViewを使用しているときに下端からのオーバースクロール効果が表示されない

public class MyListFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { 
    private SwipeRefreshLayout swipeRefreshLayout; 
    private RecyclerView recyclerView; 


    static final String[] lines = new String[]{ 
     "this is line #1", 
     "this is line #2" 
     "this is line #3" 
     "this is line #4" 
     "this is line #5" 
     "this is line #6" 
     "this is line #7" 
    }; 

    @Override 
    public void onRefresh() { 
     Log.i("QUESTION_LIST_REFRESH", "onRefresh called from SwipeRefreshLayout"); 
     new Handler().postDelayed(new Runnable() { 
      @Override public void run() { 
       swipeRefreshLayout.setRefreshing(false); 
      } 
     }, 4000); 
    } 

    @Override 
    public void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setHasOptionsMenu(true); 
    } 

    @Override 
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 

     recyclerView = (RecyclerView) view.findViewById(R.id.questions_list); 

     swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_question_list); 
     swipeRefreshLayout.setOnRefreshListener(this); 
     swipeRefreshLayout.setColorSchemeColors(
       ContextCompat.getColor(getContext(),R.color.colorPrimaryDark), 
       ContextCompat.getColor(getContext(),R.color.colorAccent)); 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.fragment_list, container, false); 

     recyclerView = (RecyclerView) view.findViewById(R.id.recycler_vew); 
     recyclerView.setHasFixedSize(true); 

     RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); 
     recyclerView.setLayoutManager(layoutManager); 


     recyclerView.setAdapter(new MyListAdapter(lines)); 

     return view; 
    } 
} 
+0

"overscroll"を終了するとはどういう意味ですか?あなたは何を達成しようとしているのかという疑問をイメージして説明してください。 –

答えて

5

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

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

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

とフラグメントからクラス:

は、ここに私のXMLです。これで問題は解決しますか?

rv.addOnScrollListener(new RecyclerView.OnScrollListener() { 


     @Override 
     public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 
      super.onScrollStateChanged(recyclerView, newState); 

      try { 

       LinearLayoutManager layoutManager = ((LinearLayoutManager) rv.getLayoutManager()); 
       int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition(); 


       Log.e("refresh", "State - " + newState + " : firstVisiblePosition" + firstVisiblePosition); 
       if (firstVisiblePosition == 0) 
        pullToRefresh.setEnabled(true); 
       else 
        pullToRefresh.setEnabled(false); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
}); 
+0

それは驚くほどうまくいった。ありがとうございました。 – emiliopedrollo

+0

@Pranav、 'pullToRefresh'とは何ですか? – ken

+0

@ken pullToRefreshはSwipeRefreshLayoutのオブジェクトです。 –

関連する問題