Created
September 6, 2021 07:46
-
-
Save alirezanazari/3369d0a010e86038a9bd4fc2c386b311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void setupViewPagerCards() { | |
List<RealmMobileBankCards> cards = new ArrayList<>(RealmMobileBankCards.getCards()); | |
if (cards.size() == 0) return; | |
binding.vpCards.setAdapter(new BankCardsAdapter(cards)); | |
binding.vpCards.setOffscreenPageLimit(cards.size() - 1); | |
initViewPager(cards.size()); | |
setupRecyclerItems(); | |
} | |
private void initViewPager(int size) { | |
binding.vpCards.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { | |
@Override | |
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | |
} | |
@Override | |
public void onPageSelected(int position) { | |
setEnableIndicator(position); | |
} | |
@Override | |
public void onPageScrollStateChanged(int state) { | |
} | |
}); | |
createViewPagerIndicators(size); | |
} | |
private void createViewPagerIndicators(int size) { | |
for (int i = 0; i < size; i++) { | |
ImageView iv = new ImageView(binding.lytIndicators.getContext()); | |
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(24, 24); | |
lp.setMargins(8, 8, 8, 8); | |
iv.setLayoutParams(lp); | |
iv.setBackgroundResource(R.drawable.indicator_slider); | |
if (i == 0) iv.setSelected(true); | |
binding.lytIndicators.addView(iv); | |
} | |
} | |
private void setEnableIndicator(int position) { | |
int count = binding.lytIndicators.getChildCount(); | |
if (position > count) return; | |
for (int i = 0; i < count; i++) { | |
binding.lytIndicators.getChildAt(i).setSelected(i == position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment