3

My layout is similar to this:

<RelativeLayout>
  <ViewPager />
  <ScrollView />
</RelativeLayout>

I have an empty view(I added to give ScrollView padding) in the scrollview whose height is equal to ViewPager's height. I am unable to scroll ViewPager as ScrollView listens to the gesture instead of ViewPager. How can this be solved?

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
  • No. in that case, ScrollView will be behind ViewPager which makes it scroll from behind the ViewPager. – Seshu Vinay Oct 09 '15 at 10:59
  • what exactly are you trying to achieve? – Muhammad Babar Oct 09 '15 at 11:02
  • a viewpager to be sticky and a scrollview scroll over it like my layout says. – Seshu Vinay Oct 09 '15 at 11:03
  • https://lh3.googleusercontent.com/PFJC6ogMgftHv73j-roXXtgnNkYH3HSiyfbVzKxJoMdJe9AXwRqiaYWzldk-yjR_QMpt=h900-rw – Seshu Vinay Oct 09 '15 at 11:04
  • I don't think you would be able to achieve two scrolls simultaneously! – Muhammad Babar Oct 09 '15 at 11:05
  • layout is similar to this. ViewPager displays a set of images. and the content below it can be scrolled over the ViewPager – Seshu Vinay Oct 09 '15 at 11:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91834/discussion-between-muhammad-babar-and-seshu-vinay). – Muhammad Babar Oct 09 '15 at 11:08
  • use framelayout over imageview & inside that framelayout do the tricky stuff to scroll – Syed Nazar Muhammad Oct 09 '15 at 11:13
  • Refer this. http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling –  Oct 09 '15 at 11:14
  • If you do not want the scrollview to intercept any click events at all ever, you can set clickable="false" and focusable="false". In that case all your touch events will go to the ViewPager. – Prateek Oct 14 '15 at 07:54
  • But how would scrolling work if no gesture is listened by ScrollView – Seshu Vinay Oct 14 '15 at 08:32
  • Could you perhaps show the wireframe of what you are trying to do ? Do you mean 100% screen is filled with a view Pager and then on bottom 20% you have a scroll view of top of it. Or, Top 80% is filled with view pager and bottom 20% we have the scroll view? A simple pictorial representation will greatly help, as i have encountered one of these cases in my past. – Henry Oct 17 '15 at 05:36
  • Do you have an image/animation of what you're trying to achieve in a more conventional file format? – PPartisan Oct 18 '15 at 21:56

1 Answers1

-1

Try out the below

activity_main

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    >

>



 <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
     >


    </android.support.v4.view.ViewPager>
</RelativeLayout>

Then Add Fragments to ur View pager

For Example here I am Adding two fragments ---FragmentA and FragmentB

  private void initialisePaging() {

        List<Fragment> fragments = new Vector<Fragment>();

        fragments.add(Fragment.instantiate(this, FragmentA.class.getName()));
        fragments.add(Fragment.instantiate(this, FragmentB.class.getName()));

        // fragments.add(Fragment.instantiate(this, TestFragment.class.getName()));
        // fragments.add(Fragment.instantiate(this, CoverPageFragment.class.getName()));

        this.mPagerAdapter = new MenuAdapterViewPager(getSupportFragmentManager(), this, MainActivty.this);

        mPager = (ViewPager) super.findViewById(R.id.viewpager);
        mPager.setOffscreenPageLimit(2);
        mPager.setAdapter(this.mPagerAdapter);


    }

Let I am Adding Similar kind of view/fragment that you have showed in the link in comments(Please ignore the ID and add a image to the ImageView(android:id="@+id/cover_image") hope u will get very similar kind UI that you need)

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    >
    <LinearLayout
        android:id="@+id/lin_coverimg"
        android:layout_width="match_parent"
        android:layout_height="380dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="10dp">
        <ImageView
            android:id="@+id/cover_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
       <ScrollView
            android:id="@+id/csv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="none">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignBottom="@+id/lin_coverimg"
                android:orientation="vertical"
                android:paddingTop="300dp">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/img_swipe"
                    android:background="#ffffff"
                    android:padding="10dp">
                    <LinearLayout
                        android:id="@+id/cover_header_layout"
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:orientation="vertical"
                        android:paddingTop="5dp">

                        <TextView
                            android:id="@+id/cover_subtittle"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="Test"
                            android:textColor="#000000"
                            android:textSize="19sp" />
                        <TextView
                            android:id="@+id/tittle"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_horizontal"
                            android:paddingTop="2dp"
                            android:text="Text"
                            android:textColor="#000000"
                            android:textSize="27sp"
                            android:textStyle="bold" />
                    </LinearLayout>
                    <TextView
                        android:id="@+id/cover_desprition"
                        android:layout_width="match_parent"
                        android:layout_height="500dp"
                        android:layout_below="@+id/cover_header_layout"
                        android:background="#ffffff"
                        android:gravity="left|fill_horizontal"
                        android:paddingTop="10dp"
                        android:textAlignment="gravity"
                        android:textColor="#000000"
                        android:textSize="18sp"
                        />
                </RelativeLayout>
            </RelativeLayout>
        </ScrollView>
    </FrameLayout>
</RelativeLayout>
Biplab
  • 564
  • 1
  • 5
  • 19