crosswall / Android-Coverflow

A beautiful coverflow lib for android
Other
910 stars 164 forks source link

Bug with scrolling - item jumps to finger position. #21

Open CHPraxis opened 7 years ago

CHPraxis commented 7 years ago

I am experiencing a strange bug with scrolling.

I am using: compile 'com.github.crosswall:Android-Coverflow:release-v1.0.4'

When I have more than two items in the coverflow, and a middle item is selected- for example, if there are three items, and the 2nd one is in the center- when I attempt to scroll, the center item jumps to where my finger touches down.

This makes scrolling very jarring. The items on the edge scroll correctly, but the item in the center leaps to my finger's location. It also prevents me from tapping on the items on the side.

My OnCreate:

      PagerContainer container = (PagerContainer) findViewById(R.id.pager_container);
        container.setOverlapEnabled(false);
        final ViewPager pager = container.getViewPager();
        pager.setOffscreenPageLimit(5);

        pager.setAdapter(new MyPagerAdapter());
        pager.setClipChildren(true);
        new CoverFlow.Builder()
                .with(pager)
                .scale(0.2f)
                .pagerMargin(0f)
                .spaceSize(0f)
                .build();

        if (pager.getAdapter().getCount() > 1) {
            pager.setCurrentItem(pager.getAdapter().getCount() / 2);
        }

My adapter:

private class MyPagerAdapter extends PagerAdapter {

        @Override
        public Object instantiateItem(ViewGroup container, int position) {

            View view = LayoutInflater.from(CoverflowActivity.this).inflate(R.layout.twitch_card_small,null);
            ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
            Picasso.with(LiveStreamActivity.this).load(mItems().get(position).getImage()).fit().into(imageView);

            //add text here!
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View)object);
        }

        @Override
        public int getCount() {
            int size = getItems().size();
            return size;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return (view == object);
        }
    }

My XML:

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="130dp"
            android:orientation="vertical">

                <me.crosswall.lib.coverflow.core.PagerContainer
                    android:id="@+id/pager_container"
                    android:layout_width="match_parent"
                    android:layout_height="125dp"
                    android:background="@color/colorBlack">

                    <android.support.v4.view.ViewPager
                        android:id="@+id/overlap_pager"
                        android:layout_width="125dp"
                        android:layout_height="125dp"
                        android:layout_gravity="center"
                        android:clipToPadding="true"/>

                </me.crosswall.lib.coverflow.core.PagerContainer>
        </LinearLayout>

Any ideas?

islamassi commented 7 years ago

in PagerContainer.java in public boolean onTouchEvent(MotionEvent ev)

Somehow, you need to comment this line in case 0: //ev.offsetLocation((float)(this.mCenter.x - this.mInitialTouch.x), (float)(this.mCenter.y - this.mInitialTouch.y));

bevzaanton commented 7 years ago

Thank you @islamassi ! You saved my day.