0

Problem

So lets say I have a ViewPager (or any other view, but lets consider ViewPager) which is contained in a RelativeLayout with AlightParent top, bottom, right and left as TRUE. like:

<com.test.MyRelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/fragment_container"
        >
    <android.support.v4.view.ViewPager
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:id="@+id/pager"
            >
    </android.support.v4.view.ViewPager>
</com.test.MyRelativeLayout>

Now, I am tracking touch events on MyRelativeLayout using OnInterceptTouchEvent() and OnTouchEvent() and want to move the top edge of the ViewPager from 0 to y (will come from OnTouchEvent()) pixels from top but maintaining the bottom edge at bottom of the screen

-I explicitly require this (maintaining the bottom edge) for some reason like the ViewPager may have a ListView and if the Pager's bottom edge is below the screen's bottom edge, I may end up in cropping the ListView's content.

Now, things are not going as expected. The bottom edge of the ViewPager seems to be hanging somewhere in the screen.

Current Implementation

So lets not get into how I have implemented this callback. I am getting the correct dy on touch Movement.

public void movePager(float dy) {        
    mPager.setTranslationY(mPager.getTranslationY() + dy);
    mPager.getLayoutParams().height = mPager.getLayoutParams().height - (int)dy;
    mPager.requestLayout();
}

My expectations from people here!

Is there any better way of doing it? Any suggestions/help/modification?

gaurav414u
  • 812
  • 13
  • 22
  • There are thousands of ways you can do that, and the one you're using seems to be correct as well. What do you mean exactly by saying "seems to be hanging somewhere in the screen"? I think the problem you have with your approach is not clear enough. Can you provide some explanation? Maybe some screens? – Bartek Lipinski Dec 16 '15 at 19:59
  • So, by hanging I mean that the viewPager stops midway and becomes funny. Keeps on trembling. I ultimately changed my implementation and got out of this misery. – gaurav414u Dec 30 '15 at 12:07

0 Answers0