本文整理匯總了Java中android.support.v7.widget.RecyclerView.setRecyclerListener方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.setRecyclerListener方法的具體用法?Java RecyclerView.setRecyclerListener怎麽用?Java RecyclerView.setRecyclerListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.setRecyclerListener方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView giphyLogoView = (ImageView) findViewById(R.id.giphy_logo_view);
GlideApp.with(this)
.load(R.raw.large_giphy_logo)
.into(giphyLogoView);
RecyclerView gifList = (RecyclerView) findViewById(R.id.gif_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
gifList.setLayoutManager(layoutManager);
RequestBuilder<Drawable> gifItemRequest = GlideApp.with(this)
.asDrawable();
ViewPreloadSizeProvider<Api.GifResult> preloadSizeProvider =
new ViewPreloadSizeProvider<>();
adapter = new GifAdapter(this, gifItemRequest, preloadSizeProvider);
gifList.setAdapter(adapter);
RecyclerViewPreloader<Api.GifResult> preloader =
new RecyclerViewPreloader<>(GlideApp.with(this), adapter, preloadSizeProvider, 4);
gifList.addOnScrollListener(preloader);
gifList.setRecyclerListener(new RecyclerListener() {
@Override
public void onViewRecycled(ViewHolder holder) {
// This is an optimization to reduce the memory usage of RecyclerView's recycled view pool
// and good practice when using Glide with RecyclerView.
GifViewHolder gifViewHolder = (GifViewHolder) holder;
GlideApp.with(MainActivity.this).clear(gifViewHolder.gifView);
}
});
}
示例2: onCreate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
adapter = new GifAdapter(this, new ArrayList<Gif>());
recyclerView.setAdapter(adapter);
new GiphyTask(Helper.getGiphyQueryUrl("pawan kalyan",
100, GiphyQueryBuilder.EndPoint.SEARCH, ""), new GiphyTask.Callback() {
@Override
public void onResponse(List<Gif> gifs) {
adapter.setGifs(gifs);
}
}).execute();
recyclerView.setRecyclerListener(new RecyclerView.RecyclerListener() {
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
GifAdapter.GifViewHolder gifHolder = (GifAdapter.GifViewHolder) holder;
gifHolder.stopPlayback();
}
});
}
示例3: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
photoSize = args.getInt(IMAGE_SIZE_KEY);
thumbnail = args.getBoolean(THUMBNAIL_KEY);
fullRequest = GlideApp.with(this)
.asDrawable()
.centerCrop()
.transition(withNoTransition());
thumbnailRequest = GlideApp.with(this)
.asDrawable()
.diskCacheStrategy(DiskCacheStrategy.DATA)
.centerCrop()
.override(Api.SQUARE_THUMB_SIZE)
.transition(withNoTransition());
preloadRequest =
thumbnail ? thumbnailRequest.clone().priority(Priority.HIGH) : fullRequest;
final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false);
final int gridMargin = getResources().getDimensionPixelOffset(R.dimen.grid_margin);
int spanCount = getResources().getDisplayMetrics().widthPixels / (photoSize + (2 * gridMargin));
grid = (RecyclerView) result.findViewById(R.id.flickr_photo_grid);
layoutManager = new GridLayoutManager(getActivity(), spanCount);
grid.setLayoutManager(layoutManager);
grid.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
outRect.set(gridMargin, gridMargin, gridMargin, gridMargin);
}
});
grid.setRecyclerListener(new RecyclerView.RecyclerListener() {
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
PhotoViewHolder photoViewHolder = (PhotoViewHolder) holder;
GlideApp.with(FlickrPhotoGrid.this).clear(photoViewHolder.imageView);
}
});
int heightCount = getResources().getDisplayMetrics().heightPixels / photoSize;
grid.getRecycledViewPool().setMaxRecycledViews(0, spanCount * heightCount * 2);
grid.setItemViewCacheSize(0);
adapter = new PhotoAdapter();
grid.setAdapter(adapter);
FixedPreloadSizeProvider<Photo> preloadSizeProvider =
new FixedPreloadSizeProvider<>(photoSize, photoSize);
RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter,
preloadSizeProvider, args.getInt(PRELOAD_KEY));
grid.addOnScrollListener(preloader);
if (currentPhotos != null) {
adapter.setPhotos(currentPhotos);
}
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
grid.scrollToPosition(index);
}
return result;
}
示例4: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View result = inflater.inflate(R.layout.flickr_photo_list, container, false);
list = (RecyclerView) result.findViewById(R.id.flickr_photo_list);
layoutManager = new LinearLayoutManager(getActivity());
list.setLayoutManager(layoutManager);
adapter = new FlickrPhotoListAdapter();
list.setAdapter(adapter);
preloadSizeProvider = new ViewPreloadSizeProvider<>();
RecyclerViewPreloader<Photo> preloader =
new RecyclerViewPreloader<>(
GlideApp.with(this), adapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);
list.addOnScrollListener(preloader);
list.setItemViewCacheSize(0);
if (currentPhotos != null) {
adapter.setPhotos(currentPhotos);
}
final GlideRequests glideRequests = GlideApp.with(this);
fullRequest = glideRequests
.asDrawable()
.centerCrop()
.placeholder(new ColorDrawable(Color.GRAY));
thumbRequest = glideRequests
.asDrawable()
.diskCacheStrategy(DiskCacheStrategy.DATA)
.override(Api.SQUARE_THUMB_SIZE)
.transition(withCrossFade());
list.setRecyclerListener(new RecyclerView.RecyclerListener() {
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
PhotoTitleViewHolder vh = (PhotoTitleViewHolder) holder;
glideRequests.clear(vh.imageView);
}
});
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
layoutManager.scrollToPositionWithOffset(index, offset);
}
return result;
}
示例5: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle args = Preconditions.checkNotNull(getArguments());
photoSize = args.getInt(IMAGE_SIZE_KEY);
thumbnail = args.getBoolean(THUMBNAIL_KEY);
fullRequest = GlideApp.with(this)
.asDrawable()
.centerCrop();
thumbnailRequest = GlideApp.with(this)
.asDrawable()
.centerCrop()
.override(Api.SQUARE_THUMB_SIZE);
preloadRequest =
thumbnail ? thumbnailRequest.clone().priority(Priority.HIGH) : fullRequest;
final View result = inflater.inflate(R.layout.flickr_photo_grid, container, false);
final int gridMargin = getResources().getDimensionPixelOffset(R.dimen.grid_margin);
int spanCount = getResources().getDisplayMetrics().widthPixels / (photoSize + (2 * gridMargin));
grid = (RecyclerView) result.findViewById(R.id.flickr_photo_grid);
layoutManager = new GridLayoutManager(getActivity(), spanCount);
grid.setLayoutManager(layoutManager);
grid.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
outRect.set(gridMargin, gridMargin, gridMargin, gridMargin);
}
});
grid.setRecyclerListener(new RecyclerView.RecyclerListener() {
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
PhotoViewHolder photoViewHolder = (PhotoViewHolder) holder;
GlideApp.with(FlickrPhotoGrid.this).clear(photoViewHolder.imageView);
}
});
int heightCount = getResources().getDisplayMetrics().heightPixels / photoSize;
grid.getRecycledViewPool().setMaxRecycledViews(0, spanCount * heightCount * 2);
grid.setItemViewCacheSize(0);
adapter = new PhotoAdapter();
grid.setAdapter(adapter);
FixedPreloadSizeProvider<Photo> preloadSizeProvider =
new FixedPreloadSizeProvider<>(photoSize, photoSize);
RecyclerViewPreloader<Photo> preloader = new RecyclerViewPreloader<>(Glide.with(this), adapter,
preloadSizeProvider, args.getInt(PRELOAD_KEY));
grid.addOnScrollListener(preloader);
if (currentPhotos != null) {
adapter.setPhotos(currentPhotos);
}
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
grid.scrollToPosition(index);
}
return result;
}
示例6: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View result = inflater.inflate(R.layout.flickr_photo_list, container, false);
list = (RecyclerView) result.findViewById(R.id.flickr_photo_list);
layoutManager = new LinearLayoutManager(getActivity());
list.setLayoutManager(layoutManager);
adapter = new FlickrPhotoListAdapter();
list.setAdapter(adapter);
preloadSizeProvider = new ViewPreloadSizeProvider<>();
RecyclerViewPreloader<Photo> preloader =
new RecyclerViewPreloader<>(
GlideApp.with(this), adapter, preloadSizeProvider, PRELOAD_AHEAD_ITEMS);
list.addOnScrollListener(preloader);
list.setItemViewCacheSize(0);
if (currentPhotos != null) {
adapter.setPhotos(currentPhotos);
}
final GlideRequests glideRequests = GlideApp.with(this);
fullRequest = glideRequests
.asDrawable()
.centerCrop()
.placeholder(new ColorDrawable(Color.GRAY));
thumbRequest = glideRequests
.asDrawable()
.diskCacheStrategy(DiskCacheStrategy.DATA)
.override(Api.SQUARE_THUMB_SIZE)
.transition(withCrossFade());
list.setRecyclerListener(new RecyclerView.RecyclerListener() {
@Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
PhotoTitleViewHolder vh = (PhotoTitleViewHolder) holder;
glideRequests.clear(vh.imageView);
}
});
if (savedInstanceState != null) {
int index = savedInstanceState.getInt(STATE_POSITION_INDEX);
int offset = savedInstanceState.getInt(STATE_POSITION_OFFSET);
layoutManager.scrollToPositionWithOffset(index, offset);
}
return result;
}