本文整理汇总了Java中android.support.v7.widget.RecyclerView.OnScrollListener类的典型用法代码示例。如果您正苦于以下问题:Java OnScrollListener类的具体用法?Java OnScrollListener怎么用?Java OnScrollListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnScrollListener类属于android.support.v7.widget.RecyclerView包,在下文中一共展示了OnScrollListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initSearch
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
private void initSearch() {
this.rvSearch.setHasFixedSize(true);
this.rvSearch.setLayoutManager(new LinearLayoutManager(this));
this.mSearchAdapter = new SearchAdapter(this.mSearchList);
this.rvSearch.setAdapter(this.mSearchAdapter);
this.rvSearch.addItemDecoration(new DividerItemDecoration(this, 1));
this.rvSearch.addOnScrollListener(new OnRecyclerLoadMoreListener() {
public void onLoadMore() {
SearcherActivity.this.sendSearchRequest(true);
}
});
this.rvSearch.addOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (SearcherActivity.this.isQuickSearch) {
KeyBoardUtils.closeAll(SearcherActivity.this.ctx);
}
}
});
}
示例2: initializeRecyclerView
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
/**
* Initializes the RecyclerView.
*
* @param adapter The adapter that provides a binding from an app-specific data set to views
* that are displayed within the RecyclerView.
* @return The RecyclerView itself.
*/
public RecyclerView initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) {
mAdapter = adapter;
mAdapter.registerAdapterDataObserver(mAdapterObserver);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
setToolbarShadowVisibility();
}
});
mItemAnimator = mRecyclerView.getItemAnimator();
return mRecyclerView;
}
示例3: onScrollStateChanged
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
switch (newState) {
case android.widget.AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
adapter.onResume();
break;
case android.widget.AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
// adapter.pause();
adapter.onResume();
break;
case android.widget.AbsListView.OnScrollListener.SCROLL_STATE_FLING:
adapter.onPause();
break;
}
if (listener2 != null)
listener2.onScrollStateChanged(recyclerView, newState);
}
示例4: AdapterRules
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
/** Default constructor for the adapter. */
public AdapterRules(RecyclerView target) {
mContext = (AppCompatActivity) target.getContext();
recycler = target;
describer = new IconDescriber(mContext);
// hasScroll is set to true the moment a nonzero scroll happens
target.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(dy == 0) return;
hasScroll = true;
recyclerView.removeOnScrollListener(this);
}
});
// retrieve the basic preferences and reload the list of options.
SharedPreferences pref = Pref.get(mContext);
loadPref(pref, Pref.FILT_SET, filt_set);
loadPref(pref, Pref.FILT_COST, filt_cost);
loadPref(pref, Pref.FILT_DEBT, filt_debt);
reload();
}
示例5: initializeResources
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
private void initializeResources() {
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1);
this.lastSeen = this.getActivity().getIntent().getLongExtra(ConversationActivity.LAST_SEEN_EXTRA, -1);
this.firstLoad = true;
OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
list.addOnScrollListener(scrollListener);
}
示例6: initLoadMore
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
private void initLoadMore() {
this.mRecyclerView.setOnScrollListener(new OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastVisibleItem = PPRecyclerView.this.mLayoutManager
.findLastVisibleItemPosition();
int totalItemCount = PPRecyclerView.this.mLayoutManager.getItemCount();
if (PPRecyclerView.this.mListener != null && !PPRecyclerView.this.isLoadMore &&
lastVisibleItem >= totalItemCount - PPRecyclerView.this.lastNum) {
PPRecyclerView.this.isLoadMore = true;
PPRecyclerView.this.mListener.loadMore();
}
}
});
}
示例7: setAbsListViewOnScrollListener
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
private void setAbsListViewOnScrollListener() {
if (mAbsListView != null) {
try {
// 通过反射获取开发者自定义的滚动监听器,并将其替换成自己的滚动监听器,触发滚动时也要通知开发者自定义的滚动监听器(非侵入式,不让开发者继承特定的控件)
// mAbsListView.getClass().getDeclaredField("mOnScrollListener")获取不到mOnScrollListener,必须通过AbsListView.class.getDeclaredField("mOnScrollListener")获取
Field field = AbsListView.class.getDeclaredField("mOnScrollListener");
field.setAccessible(true);
// 开发者自定义的滚动监听器
final AbsListView.OnScrollListener onScrollListener = (AbsListView.OnScrollListener) field.get(mAbsListView);
mAbsListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
if ((scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_FLING) && shouldHandleAbsListViewLoadingMore(mAbsListView)) {
beginLoadingMore();
}
if (onScrollListener != null) {
onScrollListener.onScrollStateChanged(absListView, scrollState);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (onScrollListener != null && !mIsLoadingMore) {
onScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例8: getRefreshView
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
/**
* 获取ListView对象
*/
protected void getRefreshView() {
int childs = getChildCount();
if (childs > 0) {
View childView = getChildAt(0);
if (childView instanceof RecyclerView) {
mRecyclerView = (RecyclerView) childView;
// 设置滚动监听器给ListView, 使得滚动的情况下也可以自动加载
mRecyclerView.setOnScrollListener(mScrollListener);
mRecyclerView.setOnScrollListener(new OnScrollListener() {
});
}
}
}
示例9: onFinishInflate
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
protected void onFinishInflate()
{
super.onFinishInflate();
this.mTitleRecycler = ((PlayRecyclerView)findViewById(2131755930));
this.mPageIndicator = ((ScalingPageIndicator)findViewById(2131755931));
ViewCompat.setImportantForAccessibility(this.mPageIndicator, 2);
getContext();
LinearLayoutManager localLinearLayoutManager = new LinearLayoutManager(0);
this.mTitleRecycler.setLayoutManager(localLinearLayoutManager);
this.mTitleRecycler.setHasFixedSize(true);
this.mTitleRecycler.setFocusable(false);
ViewCompat.setAccessibilityDelegate(this.mTitleRecycler, new AccessibilityDelegateCompat()
{
public final void onInitializeAccessibilityEvent(View paramAnonymousView, AccessibilityEvent paramAnonymousAccessibilityEvent)
{
AccessibilityRecordCompat localAccessibilityRecordCompat = AccessibilityEventCompat.asRecord(paramAnonymousAccessibilityEvent);
AccessibilityRecordCompat.IMPL.setContentDescription(localAccessibilityRecordCompat.mRecord, null);
}
});
if (Build.VERSION.SDK_INT >= 14) {
this.mTitleRecycler.addOnScrollListener(new RecyclerView.OnScrollListener()
{
@TargetApi(14)
public final void onScrolled(RecyclerView paramAnonymousRecyclerView, int paramAnonymousInt1, int paramAnonymousInt2)
{
super.onScrolled(paramAnonymousRecyclerView, paramAnonymousInt1, paramAnonymousInt2);
paramAnonymousRecyclerView.getLayoutManager();
int i = PlayHighlightsOverlayView.this.mTitleRecycler.getWidth();
int j = PlayHighlightsOverlayView.this.mTitleRecycler.getLeft() + i / 2;
for (int k = 0; k < paramAnonymousRecyclerView.getChildCount(); k++)
{
View localView = paramAnonymousRecyclerView.getChildAt(k);
float f = Math.abs(LinearLayoutManager.getDecoratedLeft(localView) + LinearLayoutManager.getDecoratedMeasuredWidth(localView) / 2 - j) / PlayHighlightsOverlayView.this.mItemWidth;
localView.setAlpha(Math.max(0.0F, 1.0F - PlayHighlightsOverlayView.this.mAlphaInterpolator.getInterpolation(f)));
}
}
});
}
}
示例10: scrollListener
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
public OnScrollListener scrollListener(LinearLayoutManager layoutManager) {
return new ScrollListener(layoutManager);
}
示例11: onCreate
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ads_reas_all);
this.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//initialize Views
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
txtCityFilter = (TextView) findViewById(R.id.txtCityFilter);
txtFilter = (TextView) findViewById(R.id.txtFilter);
txtGroup = (TextView) findViewById(R.id.txtGroup);
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
fab = (FloatingActionButton) findViewById(R.id.fab);
//initialize RecyclerView
recyclerView = (RecyclerView) findViewById(R.id.recycleView);
recyclerView.setHasFixedSize(true);
adapter = new PersonAdapter(mCommentList);
manager = new WrapContentLinearLayoutManager(this);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
recyclerView.setAdapter(adapter);
txtCityFilter.setOnClickListener(this);
txtFilter.setOnClickListener(this);
fab.setOnClickListener(this);
swipe.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
recyclerView.setClickable(false);
// mCommentList.clear();
isSwiped = true;
previousTotal = 0;
part = 0;
updateJSONdata();
}
});
/*
visibleItemCount --->> how many item can show in screen
totalItemCount --->> number of items that load in memory
firstVisibleItem --->> first item that show in list
part --->> how many item get from server in one step
*/
recyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerVie, int dx, int dy) {
super.onScrolled(recyclerVie, dx, dy);
visibleItemCount = recyclerView.getChildCount();
totalItemCount = manager.getItemCount();
firstVisibleItem = manager.findFirstVisibleItemPosition();
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
part++;
updateJSONdata();
loading = true;
}
}
});
M.setCustomFont((ViewGroup) (getWindow().getDecorView()));
}
示例12: setOnScrollListener
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
public void setOnScrollListener(OnScrollListener l) {
// hijack the scroll listener setter and have this list also notify the additional listener
mAdditionalOnScrollListener = l;
}
示例13: showRelativeUserView
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
/**
* 添加相关用户显示</br>
*
* @param users
*/
@Override
public void showRelativeUserView(List<CommUser> users) {
mAdapter.getDataSource().clear();
if (users == null || users.size() == 0) {
mMoreView.setVisibility(View.GONE);
// invalidate
mAdapter.notifyDataSetChanged();
return;
}
int itemWidth = mAdapter.computeWidth();
LayoutParams params = mRecyclerView.getLayoutParams();
if (users.size() > 4) {
mMoreView.setVisibility(View.VISIBLE);
params.width = (SearchUsersAdapter.MAX_SHOW_NUM - 1) * itemWidth;
} else {
params.width = users.size() * itemWidth;
mMoreView.setVisibility(View.GONE);
}
mRecyclerView.setLayoutParams(params);
mRecyclerView.invalidate();
mAdapter.getDataSource().addAll(users);
mAdapter.notifyDataSetChanged();
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(400);
alphaAnimation.setFillAfter(true);
LayoutAnimationController layoutAnimationController = new LayoutAnimationController(
alphaAnimation, 0.4f);
mRecyclerView.setLayoutAnimation(layoutAnimationController);
mRecyclerView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int visibleItemCount = mLinearLayoutManager.getChildCount();
int totalItemCount = mLinearLayoutManager.getItemCount();
int pastVisiblesItems = mLinearLayoutManager.findFirstVisibleItemPosition();
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
((SearchPresenter) mPresenter).loadMoreUser();
}
}
});
}
示例14: setOnScrollListener
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
public void setOnScrollListener(RecyclerView.OnScrollListener paramOnScrollListener)
{
this.mAppRecyclerViewOnScrollListener = paramOnScrollListener;
}
示例15: HistoryManager
import android.support.v7.widget.RecyclerView.OnScrollListener; //导入依赖的package包/类
/**
* Creates a new HistoryManager.
* @param activity The Activity associated with the HistoryManager.
* @param isSeparateActivity Whether the history UI will be shown in a separate activity than
* the main Chrome activity.
* @param snackbarManager The {@link SnackbarManager} used to display snackbars.
*/
@SuppressWarnings("unchecked") // mSelectableListLayout
public HistoryManager(
Activity activity, boolean isSeparateActivity, SnackbarManager snackbarManager) {
mActivity = activity;
mIsSeparateActivity = isSeparateActivity;
mSnackbarManager = snackbarManager;
mSelectionDelegate = new SelectionDelegate<>();
mSelectionDelegate.addObserver(this);
mHistoryAdapter = new HistoryAdapter(mSelectionDelegate, this,
sProviderForTests != null ? sProviderForTests : new BrowsingHistoryBridge());
// 1. Create SelectableListLayout.
mSelectableListLayout =
(SelectableListLayout<HistoryItem>) LayoutInflater.from(activity).inflate(
R.layout.history_main, null);
// 2. Initialize RecyclerView.
mRecyclerView = mSelectableListLayout.initializeRecyclerView(mHistoryAdapter);
// 3. Initialize toolbar.
mToolbar = (HistoryManagerToolbar) mSelectableListLayout.initializeToolbar(
R.layout.history_toolbar, mSelectionDelegate, R.string.menu_history, null,
R.id.normal_menu_group, R.id.selection_mode_menu_group,
R.color.default_primary_color, this);
mToolbar.setManager(this);
mToolbar.initializeSearchView(this, R.string.history_manager_search, R.id.search_menu_id);
// 4. Width constrain the SelectableListLayout.
mSelectableListLayout.configureWideDisplayStyle();
// 5. Initialize empty view.
mEmptyView = mSelectableListLayout.initializeEmptyView(
VectorDrawableCompat.create(
mActivity.getResources(), R.drawable.history_big, mActivity.getTheme()),
R.string.history_manager_empty, R.string.history_manager_no_results);
// 6. Create large icon bridge.
mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
ActivityManager activityManager = ((ActivityManager) ContextUtils
.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
int maxSize = Math.min((activityManager.getMemoryClass() / 4) * MEGABYTES_TO_BYTES,
FAVICON_MAX_CACHE_SIZE_BYTES);
mLargeIconBridge.createCache(maxSize);
// 7. Initialize the adapter to load items.
mHistoryAdapter.initialize();
// 8. Add scroll listener to page in more items when necessary.
mRecyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (!mHistoryAdapter.canLoadMoreItems()) return;
// Load more items if the scroll position is close to the bottom of the list.
LinearLayoutManager layoutManager =
(LinearLayoutManager) recyclerView.getLayoutManager();
if (layoutManager.findLastVisibleItemPosition()
> (mHistoryAdapter.getItemCount() - 25)) {
mHistoryAdapter.loadMoreItems();
recordUserActionWithOptionalSearch("LoadMoreOnScroll");
}
}});
// 9. Listen to changes in sign in state.
SigninManager.get(mActivity).addSignInStateObserver(this);
recordUserAction("Show");
}