本文整理汇总了Java中android.support.v7.widget.RecyclerView类的典型用法代码示例。如果您正苦于以下问题:Java RecyclerView类的具体用法?Java RecyclerView怎么用?Java RecyclerView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecyclerView类属于android.support.v7.widget包,在下文中一共展示了RecyclerView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
private void init() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
int[] gridNumAndWidth = calculateGridNumAndWidth();
recyclerView.setLayoutManager(new GridLayoutManager(this, gridNumAndWidth[0]));
adapter = new IconAdapter(this, gridNumAndWidth[1]);
adapter.setMode(IconAdapter.MODE_ICON_LABEL);
adapter.setOnItemClickListener(new IconAdapter.OnItemClickListener() {
@Override
public void onClick(int pos, IconBean bean) {
searchView.clearFocus();
IconDialog.newInstance(bean, false).show(getSupportFragmentManager(), "iconDialog");
}
});
recyclerView.setAdapter(adapter);
}
示例2: onCreateView
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_assignments, container, false);
vSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
vSwipeRefreshLayout.setOnRefreshListener(this);
vSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.primary));
vRecyclerView = (RecyclerView) view.findViewById(R.id.cardList);
vRecyclerView.setHasFixedSize(false);
final LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setOrientation(LinearLayoutManager.VERTICAL);
vRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// So the user didn't accidentally refresh on pulling up
vSwipeRefreshLayout.setEnabled(llm.findFirstCompletelyVisibleItemPosition() == 0);
}
});
vRecyclerView.setLayoutManager(llm);
return view;
}
示例3: animateChange
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public boolean animateChange(@NonNull RecyclerView.ViewHolder oldHolder,
@NonNull RecyclerView.ViewHolder newHolder,
@NonNull ItemHolderInfo preInfo,
@NonNull ItemHolderInfo postInfo) {
if (preInfo instanceof RecipesItemHolderInfo) {
RecipesItemHolderInfo recipesItemHolderInfo = (RecipesItemHolderInfo) preInfo;
RecipesAdapter.RecipeViewHolder holder = (RecipesAdapter.RecipeViewHolder) newHolder;
animateHeartButton(holder);
if (RecipesAdapter.ACTION_LIKE_IMAGE_DOUBLE_CLICKED.equals(recipesItemHolderInfo.updateAction)) {
animatePhotoLike(holder);
}
}
return false;
}
示例4: onCreateView
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.place_list, container, false);
// Create a list of words
final ArrayList<Place> places = new ArrayList<Place>();
places.add(new Place(R.string.name_Paris, R.string.Paris_title,
R.drawable.paris_france_logo));
places.add(new Place(R.string.paris_plage, R.string.argu_p_p,
R.drawable.paris_plage));
places.add(new Place(R.string.shopping, R.string.argu_shopping,
R.drawable.shopping_paris));
PlaceRecyclerViewAdapter adapter = new PlaceRecyclerViewAdapter(places);
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.list);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return rootView;
}
示例5: onScrollStateChanged
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
int listViewState;
switch (newState) {
case RecyclerView.SCROLL_STATE_DRAGGING:
listViewState = ListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL;
break;
case RecyclerView.SCROLL_STATE_IDLE:
listViewState = ListView.OnScrollListener.SCROLL_STATE_IDLE;
break;
case RecyclerView.SCROLL_STATE_SETTLING:
listViewState = ListView.OnScrollListener.SCROLL_STATE_FLING;
break;
default:
listViewState = UNKNOWN_SCROLL_STATE;
}
scrollListener.onScrollStateChanged(null /*view*/, listViewState);
}
示例6: onViewAttachedToWindow
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
/**
* 当RecyclerView在windows活动时获取StaggeredGridLayoutManager布局管理器,修正header和footer显示整行
*
* @param holder the RecyclerView.ViewHolder
*/
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
if (BEHAVIOR_MODE == ONLY_HEADER) {
p.setFullSpan(holder.getLayoutPosition() == 0);
} else if (BEHAVIOR_MODE == ONLY_FOOTER) {
p.setFullSpan(holder.getLayoutPosition() == mItems.size() + 1);
} else if (BEHAVIOR_MODE == BOTH_HEADER_FOOTER) {
if (holder.getLayoutPosition() == 0 || holder.getLayoutPosition() == mItems.size() + 1) {
p.setFullSpan(true);
}
}
}
}
示例7: onDraw
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
int dividerLeft = parent.getPaddingLeft();
int dividerRight = parent.getWidth() - parent.getPaddingRight();
int childCount = parent.getChildCount();
for (int i = 0; i < childCount - 1; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int dividerTop = child.getBottom() + params.bottomMargin;
int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();
mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
mDivider.draw(canvas);
}
}
示例8: onCreate
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
// Calling the RecyclerView
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setHasFixedSize(true);
Realm.init(this);
realm = Realm.getDefaultInstance();
RealmResults<StepCounts> results = realm.where(StepCounts.class).findAll();
// The number of Columns
mLayoutManager = new GridLayoutManager(this, 1);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new HistoryAdapter(results,HistoryActivity.this);
mRecyclerView.setAdapter(mAdapter);
}
示例9: onActivityCreated
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
BaseActivity activity = (BaseActivity) getActivity();
/* MastodonApi on the base activity is only guaranteed to be initialised after the parent
* activity is created, so everything needing to access the api object has to be delayed
* until here. */
api = activity.mastodonApi;
// Just use the basic scroll listener to load more accounts.
scrollListener = new EndlessOnScrollListener(layoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
AccountListFragment.this.onLoadMore(view);
}
};
recyclerView.addOnScrollListener(scrollListener);
}
示例10: onAttachedToRecyclerView
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (mSpanSizeLookup == null) {
return (isHeader(position) || isFooter(position) || isRefreshHeader(position))
? gridLayoutManager.getSpanCount() : 1;
} else {
return (isHeader(position) || isFooter(position) ||
isRefreshHeader(position)) ? gridLayoutManager.getSpanCount() :
mSpanSizeLookup.getSpanSize(gridLayoutManager,
(position - (getHeaderViewCount() + 1)));
}
}
});
}
mInnerAdapter.onAttachedToRecyclerView(recyclerView);
}
示例11: setAdapter
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
public void setAdapter(final RecyclerView.Adapter adapter) {
if (adapter != null) {
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
LogUtil.e("数据改变了 ");
// 当数据插入完成后
isLoading = false;
if (moreLoadView.getVisibility() == VISIBLE) {
moreLoadView.setVisibility(GONE);
}
if (adapter.getItemCount() == 0 && emptyView != null) {
LogUtil.e("数据为空时,显示空view");
emptyView.setVisibility(VISIBLE);
} else if (emptyView != null) {
emptyView.setVisibility(GONE);
}
}
});
display.setAdapter(adapter);
}
}
示例12: measureScrapChild
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
int heightSpec, int[] measuredDimension) {
if (position < getItemCount()) {
try {
View view = recycler.getViewForPosition(position);//fix 动态添加时报IndexOutOfBoundsException
if (view != null) {
RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
getPaddingLeft() + getPaddingRight(), p.width);
int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
getPaddingTop() + getPaddingBottom(), p.height);
view.measure(childWidthSpec, childHeightSpec);
measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
recycler.recycleView(view);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例13: drawDrawableDividerPositionStart
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
/**
* Procedure meant to handle the drawing of the intended {@link SimpleDividerItemDecoration}'s divider
* on start / left of the parent's {@link RecyclerView} item.
* @param canvas the {@link Canvas} object where the divider will be drawn.
* @param parent the parent {@link RecyclerView} for the applied {@link SimpleDividerItemDecoration}.
* @param mDivider the divider's target {@link Drawable} value.
*/
protected void drawDrawableDividerPositionStart(@NonNull final Canvas canvas, @NonNull final RecyclerView parent,
@NonNull final Drawable mDivider) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View view = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
final int left = view.getLeft() + params.leftMargin;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(canvas);
}
}
示例14: drawVertical
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
public void drawVertical(Canvas c, RecyclerView parent) {
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
final int top = child.getTop() - params.topMargin;
final int bottom = child.getBottom() + params.bottomMargin;
final int left = child.getRight() + params.rightMargin;
final int right = left + mHeightDivider.getIntrinsicWidth();
mHeightDivider.setBounds(left, top, right, bottom);
mHeightDivider.draw(c);
}
}
示例15: onCheckViewClicked
import android.support.v7.widget.RecyclerView; //导入依赖的package包/类
@Override
public void onCheckViewClicked(CheckView checkView, MediaInfo mediaInfo, RecyclerView.ViewHolder holder) {
if (mSelectionSpec.countable) {
int checkedNum = mSelectedCollection.checkedNumOf(mediaInfo);
if (checkedNum == CheckView.UNCHECKED) {
if (assertAddSelection(holder.itemView.getContext(), mediaInfo)) {
mSelectedCollection.add(mediaInfo);
notifyCheckStateChanged();
}
} else {
mSelectedCollection.remove(mediaInfo);
notifyCheckStateChanged();
}
} else {
if (mSelectedCollection.isSelected(mediaInfo)) {
mSelectedCollection.remove(mediaInfo);
notifyCheckStateChanged();
} else {
if (assertAddSelection(holder.itemView.getContext(), mediaInfo)) {
mSelectedCollection.add(mediaInfo);
notifyCheckStateChanged();
}
}
}
}