本文整理匯總了Java中android.support.v7.widget.RecyclerView.setOnScrollListener方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.setOnScrollListener方法的具體用法?Java RecyclerView.setOnScrollListener怎麽用?Java RecyclerView.setOnScrollListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.setOnScrollListener方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setParallaxHeader
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Set the view as header.
*
* @param header The inflated header
* @param view The RecyclerView to set scroll listeners
*/
public void setParallaxHeader(View header, final RecyclerView view) {
mRecyclerView = view;
mHeader = new CustomRelativeWrapper(header.getContext(), mShouldClipView);
mHeader.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mHeader.addView(header, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
view.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (mHeader != null) {
translateHeader(mRecyclerView.getLayoutManager().getChildAt(0) == mHeader ?
mRecyclerView.computeVerticalScrollOffset() : mHeader.getHeight());
}
}
});
}
示例2: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
RecyclerView view = new RecyclerView(getActivity());
view.setLayoutManager(new LinearLayoutManager(getActivity(),
LinearLayoutManager.VERTICAL, false));
view.setAdapter(mAdapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(view.getContext(),
LinearLayoutManager.VERTICAL);
view.addItemDecoration(dividerItemDecoration);
view.setOnScrollListener(new OnLoadMoreListener() {
@Override
public void onLoadMore() {
loadPage();
}
});
return view;
}
示例3: bindView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void bindView(@NonNull RecyclerView view) {
super.bindView(view);
mSwipeItemTouchListener = new SwipeItemTouchListener(view.getContext(), mGroupBasicAdapter, getContentView());
if (mSwipeCardActionEdge != -1) {
mSwipeItemTouchListener.setActionEdge(mSwipeCardActionEdge);
}
view.addOnItemTouchListener(mSwipeItemTouchListener);
view.setOnScrollListener(new RecyclerView.OnScrollListener(){
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (recyclerView != null) {
scrolledY += dy;
}
}
});
}
示例4: initRecyclerView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void initRecyclerView(){
RecyclerView recyclerView = (RecyclerView) searchActivity.findViewById(R.id.recycler);
recyclerView.setAdapter(classAdapter);
userClasses = getFormatedClasses(userClasses);
searchActivity.classAdapter = new ClassAdapter(userClasses, getApplicationContext(), recyclerView);
classAdapter = searchActivity.classAdapter;
classAdapter.setOnItemClickListener(callJoinClass());
recyclerView.setAdapter(classAdapter);
RecyclerView.LayoutManager layout = new LinearLayoutManager(application,
LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layout);
recyclerView.setOnScrollListener(new HidingScrollListener() {
@Override
public void onHide() {
searchActivity.hideViews();
}
@Override
public void onShow() {
searchActivity.showViews();
}
});
}
示例5: initViews
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void initViews() {
setContentView(R.layout.activity_share);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
// Layout Managers:
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
// Adapter:
String[] adapterData = new String[]{"Alabama", "Alaska", "Arizona", "Arkansas", "California",
"Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York",
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania",
"Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah",
"Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
mAdapter = new RecyclerViewAdapter(this, recyclerView, mDataSet);
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
recyclerView.setAdapter(mAdapter);
/* Listeners */
recyclerView.setOnScrollListener(onScrollListener);
try {
new ItemTouchBuilder()
.setList(mDataSet)
.setAdapter(mAdapter)
.setSwappable(false)
.create(recyclerView)
.attachToRecyclerView(recyclerView);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: onCreate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_webtoon_view);
// get the intent information.
inIntent = getIntent();
webtoonHashID = inIntent.getStringExtra("webtoonHashID");
chapterHashID = inIntent.getStringExtra("chapterHashID");
chapterTitle = inIntent.getStringExtra("chapterTitle");
setTitle(chapterTitle);
// Link the RecyclerView, and generate the dbManager.
webtoonViewRecyclerView = (RecyclerView)findViewById(R.id.webtoon_view_recycler_view);
dbManager = new DBManager(this);
// no need for asking the permission as WebtoonListActivity checked it.
initializeLists();
// setting the recyclerView.
WebtoonViewRecyclerAdapter adapter = new WebtoonViewRecyclerAdapter(this, webtoonImages);
webtoonViewRecyclerView.setAdapter(adapter);
webtoonViewRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// Make action bar hidden when scrolled.
// webtoonViewRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
// @Override
// public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
// super.onScrolled(recyclerView, dx, dy);
// if (dy > 40) {
// isScrolledDown = true;
// } else if (dy < -5) {
// isScrolledDown = false;
// }
// }
//
// @Override
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
// super.onScrollStateChanged(recyclerView, newState);
// if (isScrolledDown) {
// getSupportActionBar().hide();
// } else {
// getSupportActionBar().show();
// }
// }
// });
webtoonViewRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (isAtBottom(recyclerView)) {
Intent intent = new Intent(getApplicationContext(), ARToonActivity.class);
getApplicationContext().startActivity(intent);
}
}
});
}
示例7: onViewCreated
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// 實例化發布問題按鈕
btnPublish = (FloatingActionButton)view.findViewById(R.id.button_publish);
btnPublish.setOnClickListener(this);
// 實例化刷新布局
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light,
android.R.color.holo_red_light,
android.R.color.holo_green_light,
android.R.color.holo_orange_light);
TypedValue typed_value = new TypedValue();
getActivity().getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, typed_value, true);
mSwipeRefreshLayout.setProgressViewOffset(false, 0, getResources().getDimensionPixelSize(typed_value.resourceId));
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// 下拉刷新
page = 1;
new LoadQuestionList().execute();
}
});
mSwipeRefreshLayout.setRefreshing(true);
// 實例化RecyclerView
mRecyclerView = (RecyclerView) view.findViewById(R.id.question_list);
final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new QuestionViewAdapter(getActivity(), mList);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
// 達到底部加載更多
loading = false;
mSwipeRefreshLayout.setRefreshing(true);
new LoadQuestionList().execute();
}
}
// 自動隱藏發布按鈕
if (Math.abs(dy) > ScrollOffset)
if (dy > 0)
btnPublish.hide(true);
else
btnPublish.show(true);
}
});
// 開始載入問題操作
new LoadQuestionList().execute();
}