、(オーバースクロール上部と下部の両方に取り組んでいる)、私はこのように私のレイアウトを持っている:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<...<custom view>...SwipeRefreshWrapper
android:id="@+id/swiperefresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="@+id/video_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include layout="@layout/include_video_list_empty_view"/>
<include layout="@layout/include_watchlist_empty_view"/>
</FrameLayout>
<SwipeRefreshWrapper>
そして、私のSwipeRefreshWrapper実装次のようになります。私の断片Iのセットアップで次に
/**
* This Class ensures that a SwipeRefreshLayout will only refresh if the
* list it wraps cannot scroll up anymore, (that it is at the top). Otherwise
* when the user attempts to scroll up from the middle of the list, the refresh
* will trigger. This is necessary for custom List implementations, (or
* RecyclerViews), only.
*/
public class SwipeRefreshWrapper extends SwipeRefreshLayout {
private ScrollResolver mScrollResolver;
public SwipeRefreshWrapper(Context context) {
super(context);
}
public SwipeRefreshWrapper(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollResolver(ScrollResolver scrollResolver) {
mScrollResolver = scrollResolver;
}
@Override
public boolean canChildScrollUp() {
if(mScrollResolver != null){
return mScrollResolver.canScrollUp();
} else {
return super.canChildScrollUp();
}
}
public static interface ScrollResolver{
public boolean canScrollUp();
}
}
SwipeRefreshLayout:
/**
* Initializes PullToRefresh handler
*/
private void initPullToRefresh() {
mSwipeRefreshLayout = (SwipeRefreshWrapper) mView.findViewById(R.id.swiperefresh_layout);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
mSwipeRefreshLayout.setScrollResolver(new SwipeRefreshWrapper.ScrollResolver() {
@Override
public boolean canScrollUp() {
return mVideoRecycler.canScrollVertically(-1);
}
});
mSwipeRefreshLayout.setOnRefreshListener(...)
}
レイアウトやアクティビティ/フラグメントコード(または少なくともこの問題に関連する部分)を投稿できる場合は、本当に役に立ちます。 – Jlange
これはレイアウトやコードの問題ではなく、アンドロイドスタジオテンプレート(ScrollingActivity)を使用してデフォルトのアクティビティを作成しました。私のアプリではオーバースキャン効果がありません。 – Dahnark
さて、既定のScrollingActivityで新しいアプリケーションを作成しましたが、これと同じScrollingActivityの古いアプリケーションでオーバースキャンが発生したときにオーバースキャンされませんでした。最新のサポートライブラリでAndroid Studio 3.0ベータ2を使用しています。おそらく、このバグの原因は何ですか? – Dahnark