本文整理匯總了Java中android.support.v7.widget.LinearSnapHelper類的典型用法代碼示例。如果您正苦於以下問題:Java LinearSnapHelper類的具體用法?Java LinearSnapHelper怎麽用?Java LinearSnapHelper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LinearSnapHelper類屬於android.support.v7.widget包,在下文中一共展示了LinearSnapHelper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
private void init(Context context) {
initSound();
setOverScrollMode(OVER_SCROLL_NEVER);
setHasFixedSize(true);
mDecorationPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mUnitTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mDecorationRect = new Rect();
mDecoration = new DefaultDecoration();
mAdapter = new WheelAdapter(context);
super.setAdapter(mAdapter);
mLayoutManager = new WheelPickerLayoutManager(this);
super.setLayoutManager(mLayoutManager);
new LinearSnapHelper().attachToRecyclerView(this);
}
示例2: initGalleryWhenImagesAreAvailable
import android.support.v7.widget.LinearSnapHelper; //導入依賴的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.LinearSnapHelper; //導入依賴的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: onBindViewHolder
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL ||
snap.getGravity() == Gravity.CENTER_VERTICAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
holder.recyclerView.setOnFlingListener(null);
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new GravityPagerSnapHelper(Gravity.START).attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext()));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
|| snap.getGravity() == Gravity.END
|| snap.getGravity() == Gravity.CENTER_HORIZONTAL,
snap.getGravity() == Gravity.CENTER, snap.getApps()));
}
示例5: onBindViewHolder
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
@Override public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(
new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL,
false));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL
|| snap.getGravity() == Gravity.CENTER_VERTICAL
|| snap.getGravity() == Gravity.CENTER) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(),
snap.getGravity() == Gravity.CENTER_HORIZONTAL ? LinearLayoutManager.HORIZONTAL
: LinearLayoutManager.VERTICAL, false));
holder.recyclerView.setOnFlingListener(null);
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(
new LinearLayoutManager(holder.recyclerView.getContext()));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
|| snap.getGravity() == Gravity.END
|| snap.getGravity() == Gravity.CENTER_HORIZONTAL, snap.getApps()));
}
示例6: parseAllSections
import android.support.v7.widget.LinearSnapHelper; //導入依賴的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));
}
}
}
示例7: initSnapHelper
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
/**
* 初始化SnapHelper
*
* @param helper
*/
public void initSnapHelper(int helper) {
switch (helper) {
case GalleryRecyclerView.LinearySnapHelper:
mLinearySnapHelper = new LinearSnapHelper();
mLinearySnapHelper.attachToRecyclerView(mGalleryRecyclerView);
break;
case GalleryRecyclerView.PagerSnapHelper:
mPagerSnapHelper = new PagerSnapHelper();
mPagerSnapHelper.attachToRecyclerView(mGalleryRecyclerView);
break;
}
}
示例8: onCreateView
import android.support.v7.widget.LinearSnapHelper; //導入依賴的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;
}
示例9: setupSectionView
import android.support.v7.widget.LinearSnapHelper; //導入依賴的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);
}
示例10: initView
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
@Override
protected void initView() {
mActivity = (AppCompatActivity) mContext;
mToolbar = (Toolbar) mContext.findViewById(R.id.toolbar_daily_fragment);
mActivity.setSupportActionBar(mToolbar);
mActivity.setTitle(R.string.bottom_bar_gank);
mToolbar.inflateMenu(R.menu.main_menu);
mRecyclerView = (RecyclerView) mContext.findViewById(R.id.daily_recycler_view);
LinearLayoutManager manager = new LinearLayoutManager(mContext);
manager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecyclerView.setLayoutManager(manager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mSnapHelper = new LinearSnapHelper();
if (mRecyclerView.getOnFlingListener() == null) {
mSnapHelper.attachToRecyclerView(mRecyclerView);
}
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
LinearLayoutManager layoutManager
= (LinearLayoutManager) recyclerView.getLayoutManager();
int totalItemCount = layoutManager.getItemCount();
int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
if (totalItemCount <= lastVisibleItem + 1) {
loadDailyData(mPage+=1);
}
}
});
mProgressBar = (ProgressBar) mContext.findViewById(R.id.daily_loading_progress_bar);
mFailureTextView = (TextView) mContext.findViewById(R.id.daily_get_failure_tip);
}
示例11: onBindViewHolder
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL ||
snap.getGravity() == Gravity.CENTER_VERTICAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
new GravityPagerSnapHelper(Gravity.START).attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext()));
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
|| snap.getGravity() == Gravity.END
|| snap.getGravity() == Gravity.CENTER_HORIZONTAL,
snap.getGravity() == Gravity.CENTER, snap.getApps()));
}
示例12: onCreate
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bt_drop_in_activity);
mBottomSheet = findViewById(R.id.bt_dropin_bottom_sheet);
mLoadingViewSwitcher = findViewById(R.id.bt_loading_view_switcher);
mSupportedPaymentMethodsHeader = findViewById(R.id.bt_supported_payment_methods_header);
mSupportedPaymentMethodListView = findViewById(R.id.bt_supported_payment_methods);
mVaultedPaymentMethodsContainer = findViewById(R.id.bt_vaulted_payment_methods_wrapper);
mVaultedPaymentMethodsView = findViewById(R.id.bt_vaulted_payment_methods);
mVaultedPaymentMethodsView.setLayoutManager(new LinearLayoutManager(this,
LinearLayoutManager.HORIZONTAL, false));
new LinearSnapHelper().attachToRecyclerView(mVaultedPaymentMethodsView);
try {
mBraintreeFragment = getBraintreeFragment();
} catch (InvalidArgumentException e) {
finish(e);
return;
}
if (savedInstanceState != null) {
mSheetSlideUpPerformed = savedInstanceState.getBoolean(EXTRA_SHEET_SLIDE_UP_PERFORMED,
false);
mDeviceData = savedInstanceState.getString(EXTRA_DEVICE_DATA);
}
slideUp();
}
示例13: onCreate
import android.support.v7.widget.LinearSnapHelper; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 1
this.cardRecyclerView = (RecyclerView)findViewById(R.id.recycler_view);
this.cardRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
this.cardAdapter = new CardAdapter(this);
this.cardRecyclerView.setAdapter(this.cardAdapter);
// 4
LinearSnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(this.cardRecyclerView);
this.cardRecyclerView.setOnFlingListener(snapHelper);
this.cardRecyclerView.addItemDecoration(new VerticalOffsetDecoration(this)); // 9
// 2
List<LocationInformation> locations = new ArrayList<>();
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
// 3
this.cardAdapter.setItems(locations);
}
示例14: setupRecyclerView
import android.support.v7.widget.LinearSnapHelper; //導入依賴的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);
}
}
}
});
}
示例15: initRecyclerView
import android.support.v7.widget.LinearSnapHelper; //導入依賴的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);
}