本文整理汇总了Java中android.support.v7.widget.SnapHelper.attachToRecyclerView方法的典型用法代码示例。如果您正苦于以下问题:Java SnapHelper.attachToRecyclerView方法的具体用法?Java SnapHelper.attachToRecyclerView怎么用?Java SnapHelper.attachToRecyclerView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.SnapHelper
的用法示例。
在下文中一共展示了SnapHelper.attachToRecyclerView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void init(Context context) {
inflate(context, R.layout.home_list_wrapper, this);
ButterKnife.bind(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context) {
@Override
protected int getExtraLayoutSpace(RecyclerView.State state) {
return 200;
}
};
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(linearLayoutManager);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.START);
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setMotionEventSplittingEnabled(false);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
}
示例2: initGalleryWhenImagesAreAvailable
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void initGalleryWhenImagesAreAvailable() {
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.gallery);
recyclerView.setHasFixedSize(true);
CenterLayoutManager layoutManager = new CenterLayoutManager(context, CenterLayoutManager.HORIZONTAL, false);
SnapHelper snapHelper = new LinearSnapHelper();
if (recyclerView.getOnFlingListener() == null) {
snapHelper.attachToRecyclerView(recyclerView);
}
recyclerView.setLayoutManager(layoutManager);
PlacesGalleryAdapter adapter = new PlacesGalleryAdapter(context,
imageUrls,
(ImageView) findViewById(R.id.singleImage),
(TextView) findViewById(R.id.size),
recyclerView,
languageHelper);
if (this.onClickCallback != null) {
adapter.setCallback(this.onClickCallback);
}
recyclerView.setAdapter(adapter);
}
示例3: initRecycler
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void initRecycler(@NonNull RecyclerView recyclerView) {
LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView.getContext(), VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new MultiColoredAdapter(getChildQuantity(), getChildLayoutId()));
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(recyclerView);
}
示例4: init
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void init(View view) {
unbinder = ButterKnife.bind(this, view);
mActivity = (AppCompatActivity) getActivity();
mActivity.setSupportActionBar(toolbar);
ActionBar actionBar = mActivity.getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
toolbar.setBackgroundColor(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mActivity.getWindow().setStatusBarColor(Utils.getDarkColor(color));
}
toolbar.setTitle(title);
LinearLayoutManager layoutManager
= new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.TOP);
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setMotionEventSplittingEnabled(false);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(adapter);
}
示例5: init
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void init(View view) {
unbinder = ButterKnife.bind(this, view);
LinearLayoutManager layoutManager
= new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.TOP);
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setMotionEventSplittingEnabled(false);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(adapter);
}
示例6: init
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void init(Context context) {
inflate(context, R.layout.detail_similar_movies_wrapper, this);
ButterKnife.bind(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(linearLayoutManager);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.START);
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setMotionEventSplittingEnabled(false);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
}
示例7: init
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void init(Context context) {
inflate(context, R.layout.detail_images_wrapper, this);
ButterKnife.bind(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(linearLayoutManager);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.END);
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setMotionEventSplittingEnabled(false);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
}
示例8: init
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void init(Context context, @Nullable AttributeSet attrs) {
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MetalRecyclerViewPager, 0, 0);
itemMargin = (int) typedArray.getDimension(R.styleable.MetalRecyclerViewPager_itemMargin, 0f);
typedArray.recycle();
}
setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(this);
}
示例9: background
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
@Override
protected void background() {
recentlyPlayed = new SongListAdapter(getContext());
CustomLayoutManager customLayoutManager1 = new CustomLayoutManager(getContext());
customLayoutManager1.setSmoothScrollbarEnabled(true);
customLayoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
SnapHelper startSnapHelper = new StartSnapHelper();
recentlyAdding.setLayoutManager(customLayoutManager1);
recentlyAdding.setNestedScrollingEnabled(false);
recentlyAdding.setVerticalScrollBarEnabled(false);
recentlyAdding.setHorizontalScrollBarEnabled(false);
songListAdapter.setLayoutId(R.layout.recent_list);
recentlyAdding.setScrollBarSize(0);
recentlyAdding.setAdapter(songListAdapter);
songListAdapter.setOnItemClickListener(onClicks);
recentlyAdding.setItemAnimator(new DefaultItemAnimator());
recentlyAdding.setHasFixedSize(true);
startSnapHelper.attachToRecyclerView(recentlyAdding);
getLoaderManager().initLoader(trackloader, null, RecentFragment.this);
CustomLayoutManager customLayoutManager = new CustomLayoutManager(getContext());
customLayoutManager.setSmoothScrollbarEnabled(true);
customLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recentlyPlaying.setLayoutManager(customLayoutManager);
recentlyPlaying.setNestedScrollingEnabled(false);
recentlyPlaying.setVerticalScrollBarEnabled(false);
recentlyPlaying.setHorizontalScrollBarEnabled(false);
recentlyPlayed.setLayoutId(R.layout.recent_list);
recentlyPlaying.setScrollBarSize(0);
recentlyPlaying.setAdapter(recentlyPlayed);
recentlyPlayed.setOnItemClickListener(onClick);
recentlyPlaying.setItemAnimator(new DefaultItemAnimator());
recentlyPlaying.setHasFixedSize(true);
startSnapHelper.attachToRecyclerView(recentlyPlaying);
getLoaderManager().initLoader(recentloader, null, recentPlaying);
}
示例10: parseAllSections
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void parseAllSections(int i, ViewHolder viewholder) {
if (viewholder.recyclerView != null) {
SnapHelper snapHelper = new LinearSnapHelper();
viewholder.recyclerView.setOnFlingListener(null);
snapHelper.attachToRecyclerView(viewholder.recyclerView);
ArrayList arrayList = (ArrayList) dataSet.get(i);
if (arrayList.isEmpty()) {
return;
}
Object something = arrayList.get(0);
if (something instanceof Artist) {
viewholder.recyclerView.setLayoutManager(new GridLayoutManager(activity, 1, GridLayoutManager.HORIZONTAL, false));
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new ArtistAdapter(activity, (ArrayList<Artist>) arrayList, R.layout.item_artist, false, null));
} else if (something instanceof Album) {
viewholder.recyclerView.setLayoutManager(new GridLayoutManager(activity, 1, GridLayoutManager.HORIZONTAL, false));
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new AlbumAdapter(activity, (ArrayList<Album>) arrayList, R.layout.pager_item, false, null));
} else if (something instanceof Playlist) {
viewholder.recyclerView.setLayoutManager(new LinearLayoutManager(activity));
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new PlaylistAdapter(activity, (ArrayList<Playlist>) arrayList, R.layout.item_list, null));
} else if (something instanceof Song) {
GridLayoutManager layoutManager = new GridLayoutManager(activity, 1, LinearLayoutManager.HORIZONTAL, false);
viewholder.recyclerView.setLayoutManager(layoutManager);
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new SongAdapter(activity, (ArrayList<Song>) arrayList, R.layout.item_image, false, null));
}
}
}
示例11: onCreateView
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_discover_games, container, false);
GridLayoutManager popularGamesLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
GridLayoutManager mostAnticipatedGamesLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
GridLayoutManager upcomingGamesLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
RecyclerView popularGamesRecyclerView = (RecyclerView) view.findViewById(R.id.popular_games_list);
RecyclerView mostAnticipatedGamesRecyclerView = (RecyclerView) view.findViewById(R.id.most_anticipated_games_list);
RecyclerView upcomingGamesRecyclerView = (RecyclerView) view.findViewById(R.id.upcoming_games_list);
mContent = (RelativeLayout) view.findViewById(R.id.content);
mContentLoading = (RelativeLayout) view.findViewById(R.id.content_loading_progress);
// TODO: check https://github.com/rubensousa/RecyclerViewSnap
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(popularGamesRecyclerView);
helper.attachToRecyclerView(mostAnticipatedGamesRecyclerView);
helper.attachToRecyclerView(upcomingGamesRecyclerView);
popularGamesRecyclerView.setLayoutManager(popularGamesLayoutManager);
popularGamesRecyclerView.setAdapter(mPopularGamesAdapter);
mostAnticipatedGamesRecyclerView.setLayoutManager(mostAnticipatedGamesLayoutManager);
mostAnticipatedGamesRecyclerView.setAdapter(mMostAnticipatedGamesAdapter);
upcomingGamesRecyclerView.setLayoutManager(upcomingGamesLayoutManager);
upcomingGamesRecyclerView.setAdapter(mUpcomingGamesAdapter);
return view;
}
示例12: setupSectionView
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void setupSectionView(RecyclerView recyclerView, @SectionVO.Type int type) {
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(true);
SectionAdapter adapter = new SectionAdapter(this, type, this);
recyclerView.setAdapter(adapter);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
}
示例13: setupRecyclerView
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
void setupRecyclerView()
{
adapter = new AdapterHorizontal(dataset,getActivity(),this);
reviewsList.setAdapter(adapter);
linearLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
reviewsList.setLayoutManager(linearLayoutManager);
SnapHelper helper = new LinearSnapHelper();
// helper.onFling(10,10);
helper.attachToRecyclerView(reviewsList);
reviewsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(dataset!=null && dataset.size()>0)
{
int position = linearLayoutManager.findFirstVisibleItemPosition();
if(position!=RecyclerView.NO_POSITION)
{
notifyListItemClick(position);
}
}
}
});
}
示例14: initRecyclerView
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
private void initRecyclerView() {
matrixApiLocationRecyclerViewAdapter = new MatrixApiLocationRecyclerViewAdapter(this,
matrixLocationList);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(),
LinearLayoutManager.HORIZONTAL, true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(matrixApiLocationRecyclerViewAdapter);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
}
示例15: background
import android.support.v7.widget.SnapHelper; //导入方法依赖的package包/类
@Override
protected void background() {
songListAdapter.setLayoutId(R.layout.song_list);
albumListAdapter = new AlbumListAdapter(getContext());
albumListAdapter.setLayoutID(R.layout.recent_list);
SnapHelper startSnapHelper = new StartSnapHelper();
CustomLayoutManager customLayoutManager = new CustomLayoutManager(getContext());
customLayoutManager.setSmoothScrollbarEnabled(true);
customLayoutManager.setOrientation(CustomLayoutManager.HORIZONTAL);
albumrv.setAdapter(albumListAdapter);
albumrv.setLayoutManager(customLayoutManager);
albumrv.setHasFixedSize(true);
albumrv.setNestedScrollingEnabled(false);
albumrv.setVerticalScrollBarEnabled(false);
albumrv.setHorizontalScrollBarEnabled(false);
albumrv.setScrollBarSize(0);
startSnapHelper.attachToRecyclerView(albumrv);
CustomLayoutManager c = new CustomLayoutManager(getContext());
c.setSmoothScrollbarEnabled(true);
rv.setAdapter(songListAdapter);
rv.addItemDecoration(new DividerItemDecoration(getContext(), 75, false));
rv.setLayoutManager(c);
rv.setHasFixedSize(true);
songListAdapter.setOnItemClickListener(mOnClick);
songListAdapter.setOnLongClickListener(onLongClick);
albumListAdapter.setOnItemClickListener(mOnClickAlbum);
loadTrak();
if (((MainActivity) getActivity()) != null) {
AppCompatActivity appCompatActivity = ((MainActivity) getActivity());
if (appCompatActivity != null && appCompatActivity.getSupportActionBar() != null) {
appCompatActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
appCompatActivity.setSupportActionBar(toolbar);
}
}
}