Fragment in ViewPager not restored after popBackStack

After a lengthy investigation it turns out to be a problem with the fragment manager. When using a construct like the one above the fragment transaction to reattach the fragment to the page list is silently discarded. It is basically the same problem that causes a java.lang.IllegalStateException: Recursive entry to executePendingTransactions when trying to alter … Read more

Android ViewPager padding/margin between page fragments

In Support Package, r4 you can use these methods: setPageMargin(int marginPixels) setPageMarginDrawable(Drawable) setPageMarginDrawable(int) in ViewPager class. I don’t know why this doesn’t have equivalent in XML 🙁 If you need use dip unit you can use this method: public static int convertDip2Pixels(Context context, int dip) { return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics()); }

How can we work-around the blank title in PagerTitleStrip and PagerTabStrip?

An interim solution while waiting for a patched release is to use a copy of the latest known good version of these classes (22.1.0) instead of the one bundled with the support library. Drop the attached files into your project and setup your ViewPager with these classes instead. Note: do not change their package name … Read more

How to snap RecyclerView items so that every X items would be considered like a single unit to snap to?

SnapHelper supplies the necessary framework for what you are attempting, but it needs to be extended to handle blocks of views. The class SnapToBlock below extends SnapHelper to snap to blocks of views. In the example, I have used four views to a block but it can be more or less. Update: The code has … Read more

How can I detect a click in an onTouch listener?

Masoud Dadashi’s answer helped me figure it out. here is how it looks in the end. viewPager.setOnTouchListener(new OnTouchListener() { private int CLICK_ACTION_THRESHOLD = 200; private float startX; private float startY; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: startX = event.getX(); startY = event.getY(); break; case MotionEvent.ACTION_UP: float endX = … Read more

tech